10167-birthday Cake
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=107&page=show_ problem&problem=1108
Background
Lucy and Lily are twins. This is their birthday. Mother buys a birthday cake for them. Now we put the cake onto a Descartes coordinate. Its center was at (0,0), and the cake's length of radius is 100.
There are 2N (N is an 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 treated fairly, that means, the shape of the two halves must is the same (that means the Beelin E 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 are 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 was at least one solution.
Input
The input file contains several scenarios. Each of them consists of 2 parts:the-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
This article URL address: http://www.bianceng.cn/Programming/sjjg/201410/45369.htm
For each scenario, the print a line containing two numbers a and B. There should is a space between them. If There are many solutions, you can only print one of them.
Sample Input
2
-20
-30
-10-50
10-5
0
Sample Output
0 1
Enumeration A,b.
Complete code:
/*0.015s*/#include <cstdio> const int MAXN = 30;///does not need to be 500 so big, 30 feet int chx[101], chy[101];
int main () {int n, cnt, a, b, I;
BOOL Flag; while (scanf ("%d", &n), N) {for (i = 0; i < n * 2; ++i) scanf ("%d%d", &chx[i), &
Amp;chy[i]);
Flag = false;
for (a =-MAXN a <= maxn, ++a) {for (b =-maxn; b <= maxn; ++b) {
CNT = 0;
for (i = 0; i < n * 2; ++i) {if (chx[i] * a + chy[i] * b = 0)
{cnt = 0;
Break
else if (chx[i] * a + chy[i] * b > 0) ++cnt;
} if (cnt = n) {printf ("%d%d\n", A, b);
Flag = true;
Break } if (flag) break;
} return 0; }