uvaoj10167

       Uvaoj  10167 birthday cake

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 inte-
gers. You must give the line as form two integers A,
B (stands for Ax + By = 0) each number mustn’t in
[−500,500]. Cherries are not allowed lying on the bee-
line. 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

意思就是 分蛋糕,蛋糕分成一半,使这两个姐妹得到蛋糕上的糖一样多。


最刺激我的就是 结果了  OUPPUT,一直迷惑为什么是 0 1 ,为什不不是别的!   本题应该用 直接枚举就可以了,但是怎样的顺序呢 ,,,,,,,最后验证 什么顺序都随便, If there are many solutions, you can only print one of them. 随便那个答案都可以!!  所以 题就简单了



已经通过了,用的是C----------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>
int bee[100][2];   //有多人都用结构体,这看个人了,不影响什么速度。
int main()
{
    while(1)
{
     int n;
     scanf("%d",&n);
      if(n==0)break;    //细心呦


int i,j,p,x,y,count1=0,count2=0;
for(i = 0;i<2*n;i++)
{
scanf("%d %d",&x,&y);
bee[i][0]=x;
bee[i][1]=y;
getchar();
}


int ok = 0;
for(i = -500;i<=500;i++)
{

for(j = -500;j<=500;j++)
{
 count1 = 0;count2 = 0;
 for(p = 0 ;p<2*n;p++)
 {
 if(i*bee[p][0] + bee[p][1]*j==0)break;
  else if(i*bee[p][0] + bee[p][1]*j >0)
count1++;
  else 
count2++;
 }


  if(count1 == n && count2 == n){ok=1;break;}
}
if(ok==1)break;
}


printf("%d %d\n",i,j);




}
return 0;


}

你可能感兴趣的:(易困惑的地方直接枚举简单暴力)