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. 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
本文URL地址:http://www.bianceng.cn/Programming/sjjg/201410/45369.htm
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即可。
完整代码:
/*0.015s*/ #include <cstdio> const int maxn = 30;///不需要500那么大,30足矣 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], &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; }
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索background
is
happy birthday、cube escape birthday、birthday、happy birthday花体字、birthday cake,以便于您获取更多的相关知识。