Uva10167(Birthday Cake)

题目大意,给定圆心在原点的一个圆内的2*n个整点,求由AX+BY=0(A,B均为-500到500的整数)确定的一条直线,使得直线两边的点一样多,点不允许在直线上。

由于题中数据均为有限的小整数,且时限不严,所以直接枚举即可。

View Code
 1 #include <stdio.h>
 2 #define N 100
 3 int x[N],y[N];
 4 int main()
 5 {
 6     int i,n,a,b,cnt,ok;
 7     while(scanf("%d",&n)&&n)
 8     {
 9         for(i=0;i<2*n;i++)  scanf("%d%d",&x[i],&y[i]);
10         for(a=-500,ok=0;!ok&&a<=500;a++)
11         {
12             for(b=-500;!ok&&b<=500;b++)
13             {
14                 if(!a&&!b)  continue;
15                 for(i=0,cnt=0;i<2*n;i++)
16                 {
17                     if(a*x[i]+b*y[i]==0 || cnt>n)    break;
18                     if(a*x[i]+b*y[i]>0) cnt++;
19                 }
20                 if(cnt==n&&i==2*n)
21                 {
22                     ok=1;
23                     printf("%d %d\n",a,b);
24                 }
25             }
26         }
27     }
28     return 0;
29 }
原文地址:https://www.cnblogs.com/algorithms/p/2446344.html