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
  • 相关阅读:
    Linux网络编程必看书籍推荐
    SpringMVC DispatcherServlet初始化过程
    freemarker写select组件(五)
    hdu 1009 FatMouse&#39; Trade
    新IOS编程语言 Swift 新编译器Xcode6
    NoSQL数据库:数据的一致性
    POJ 3041 Asteroids
    POJ 3342 Party at Hali-Bula (树形dp 树的最大独立集 判多解 好题)
    __repr__与__str__
    HDU 4950 Monster(公式)
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3864943.html
Copyright © 2011-2022 走看看