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
  • 相关阅读:
    170619、springboot编程之HelloWorld
    170616、解决 java.lang.IllegalArgumentException: No converter found for return value of type: class java.util.ArrayList
    170615、spring不同数据库数据源动态切换
    pytest文档10-命令行传参
    pytest文档9-参数化parametrize
    pytest文档8-html报告报错截图+失败重跑
    pytest文档7-pytest-html生成html报告
    定位对应关系
    ADB 无线连接
    command failed shell "ps 'uiautomator'"的解决方式
  • 原文地址:https://www.cnblogs.com/qscqesze/p/3864943.html
Copyright © 2011-2022 走看看