zoukankan      html  css  js  c++  java
  • UVa 10167 Birthday Cake

     Problem G. Birthday Cake 

    Background

    Lucy and Lily are twins. Today is their birthday. Mother buys a birthday cake for them.Now we put the cake onto a Descartes coordinate. Its center is at (0,0), and the cake's length of radius is 100.

    There are 2N (N is a integer, 1<=N<=50) cherries on the cake. Mother wants to cut the cake into two halves with a knife (of course a beeline). The twins would like to be treated fairly, that means, the shape of the two halves must be the same (that means the beeline must go through the center of the cake) , and each half must have N cherrie(s). Can you help her?

    Note: the coordinate of a cherry (x , y) are two integers. You must give the line as form two integers A,B(stands for Ax+By=0), each number in the range [-500,500]. Cherries are not allowed lying on the beeline. For each dataset there is at least one solution.

    Input

    The input file contains several scenarios. Each of them consists of 2 parts: The first part consists of a line with a number N, the second part consists of 2N lines, each line has two number, meaning (x,y) .There is only one space between two border numbers. The input file is ended with N=0.

    Output

    For each scenario, print a line containing two numbers A and B. There should be a space between them. If there are many solutions, you can only print one of them.

    Sample Input

    2
    -20 20
    -30 20
    -10 -50
    10 -5
    0
    

    Sample Output

    0 1
     1 #include<iostream>  
     2 #include<string.h>  
     3 #include<stdio.h>  
     4 #include<ctype.h>  
     5 #include<algorithm>  
     6 #include<stack>  
     7 #include<queue>  
     8 #include<set>  
     9 #include<math.h>  
    10 #include<vector>  
    11 #include<map>  
    12 #include<deque>  
    13 #include<list>  
    14 using namespace std;
    15  int j,n,m,sum,x[110],y[110]; 
    16        
    17  int main()
    18  {
    19      int a,b,flag=0;
    20      while(true)
    21      {
    22          scanf("%d",&n);
    23          if(n==0) break;
    24          m=2*n;
    25          for(int i=1;i<=m;i++)
    26          cin>>x[i]>>y[i];
    27          flag=0;
    28          for(a=-500;a<=500;a++)
    29          {
    30              for(b=-500;b<=500;b++)
    31              {
    32                   sum=0;
    33                  for(int i=1;i<=m;i++)
    34                  {
    35                      if((a*x[i]+b*y[i])<0) 
    36                      sum++;
    37                      if((a*x[i]+b*y[i])==0) 
    38                      break;
    39                  }
    40                  if(sum==n)
    41                 {
    42                       flag=1;
    43                       printf("%d %d
    ",a,b);
    44                       break;
    45                   }
    46               }
    47               if(flag==1) break;
    48           }
    49      }
    50      
    51      return 0;
    52  }
    View Code
  • 相关阅读:
    RabbitMQ修改端口号和心跳时间
    RabbitMQ常用命令行
    机票分页存储过程!
    Sql Server随机取数据
    Entity framewok 如何实现多条记录作为一条取出, for xml path如何实现
    AJAX请求时status返回状态明细表 readyState的五种状态
    最小化到托盘,右键退出
    post注入及提权思路
    MySQL提权之user.MYD中hash破解方法
    鸡肋提权之变态root利用
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3864943.html
Copyright © 2011-2022 走看看