您的位置:首页 > 其它

Birthday Cake——直线分割

2015-01-29 08:21 579 查看


 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

题意:一个蛋糕,放了2*N个樱桃,过圆心将这块蛋糕一刀切开,使得每一块都有N个樱桃,

切开的线方程为:Ax+By = 0,已知A,B的范围在【-500,500】求A,B的一个可能值

解析:所求值的范围已给出,可以进行暴力求解,带进去A,B的一个值,如果能将樱桃平均分成两份,直接输出值就可。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

struct po
{
int i,j;
};
po point[1000];

int main()
{
int n,x,y,z,a,b,bj = 1,num1,num2;
while(~scanf("%d",&n),n)
{
for(x = 0; x < 2*n; x++)
{
scanf("%d%d",&point[x].i,&point[x].j);
}
bj = 1;
for(a = -500; a <= 500; a++)
{
if(a == 0)
continue;
for(b = -500; b <= 500; b++)
{
num1 = 0;
num2 = 0;
for(x = 0; x < 2*n; x++)
{
if(a*point[x].i + b*point[x].j > 0)
num1++;
else if(a*point[x].i + b*point[x].j < 0)
num2++;
else if(a*point[x].i + b*point[x].j == 0)
{
break;
}
}
if(num1 == num2 && num1 == n)
{
printf("%d %d\n",a,b);
bj = 0;
break;
}
}
if(bj == 0)
break;
}
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息