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

切一刀平分樱桃,直线必过原点,无法直接枚举斜率,直接枚举A,B需要一定的范围,虽然A,B取整数,范围还是太大,

可以做蛋糕(圆)的外接正方形。则正方形上的整数点到原点的斜率和圆上点到原点的斜率一一对应,正方形坐标范围-100-100,于是枚举范围就产生了

#include<stdio.h>
int a[110][2],sum,n,x,y,i,j,k,k1,k2;
int main()
{while (scanf("%d",&n),n)
 {sum=0;
  for (i=1;i<=2*n;i++)
  {scanf("%d%d",&x,&y);
   if (x*x+y*y<=10000)
   {++sum;
    a[sum][0]=x;
    a[sum][1]=y;
   }
  }
  for (i=-100;i<=100;i++)
  for (j=-100;j<=100;j++)
  {k1=0; k2=0;
   for (k=1;k<=sum;k++)
   {if (i*a[k][0]+j*a[k][1]>0) ++k1;
    if (i*a[k][0]+j*a[k][1]<0) ++k2;
    if (i*a[k][0]+j*a[k][1]==0)break;
   }
   if ((k1==n)&&(k2==n))
   {printf("%d %d\n",i,j);goto there;}
  }
  there :;
 }
 return 0;
}


 

你可能感兴趣的:(Integer,input,each,border,dataset,Numbers)