Original question:
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 was at (0,0), and the cake's length of radius is 100.
There is 2N (N was a integer, 1≤n≤50) cherries on the cake. Mother wants to cut the cake into and halves with a knife (of course a beeline). The twins would like to being treated fairly, that means, the shape of the and the halves must is the same (that means the Beelin E must go through the center of the cake), and each half must has N Cherrie (s). Can you help her?
note:the coordinate of a cherry (x, y) are and integers. You must give the line as form a integers a, B (stands for Ax + by = 0) Each number mustn ' t in [−500,500]. Cherries is not allowed lying on the beeline. For each dataset there are 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 and the second part consists of 2N lines
has a number, meaning (x, y). There is only one space between the border numbers. The input file
is ended with N = 0.
Output
For each scenario, the print a line containing the numbers a and B. There should be a space between
them. If There is many solutions, you can be only print one of them.
Sample Input
2
-20 20
-30 20
-10-50
10-5
0
Sample Output
0 1
Effect:
Give you a cake with a diameter of 100 and a 2*n strawberry on it. Now let's find A and b so that cutting along a straight line ax+by=0 can make two halves of the cake with the same number of strawberries. (There will be no two strawberries in a straight line)
#include <bits/stdc++.h> using namespace std;
FStream in,out;
struct point {int x, y;};
Point p[101];
int main () {Ios::sync_with_stdio (false);
int n;
while (Cin>>n,n) {for (int i=1;i<=n*2;i++) cin>>p[i].x>>p[i].y;
int flag=0,mark=0;
int cnt=0,a,b; for (int a=-500; A<=500;++a) {for (int b=-500;
B<=500;++B) {mark=cnt=0;
int i;
if (a==0&&b==0) continue;
for (i=1;i<=n*2;i++) {if (a*p[i].x+b*p[i].y==0) {
mark=1;
Break
} if (a*p[i].x+b*p[i].y<0) cnt++;
} if (cnt==n&&mark==0) {a=a;
B=b; Flag= 1;
Break
}} if (flag) break;
} cout<<a<< "" <<b<<endl;
} return 0;
}
Answer:
Feel your code ability is rough, find a bit of brute force solve problem to do. This problem just got when not carefully read the data, probably understand what meaning to start to do, the result thought for a long time also didn't think out. Later, looking at other people's reports, it was found that the range of A and B was [-500,500] and did not consider the problem of decimals. So the problem is quite simple, just enumerate each A and B on the line