暴力搜索
1 #include<cstdio> 2 3 struct node 4 { 5 int x; 6 int y; 7 }s[10000]; 8 int main() 9 { 10 //freopen("input.txt","r",stdin); 11 int a,b,n,num; 12 int i; 13 bool flag; 14 while(scanf("%d",&n) && n) 15 { 16 for(i = 0; i < 2 * n; i++) 17 scanf("%d%d",&s[i].x,&s[i].y); 18 flag = 0; 19 for(a = -500 ; a <= 500; a++) 20 { 21 for(b = -500; b <= 500; b++) 22 { 23 num = 0; 24 if(a == 0 && b == 0) continue; 25 for(i = 0; i < 2 * n; i++) 26 { 27 if(a * s[i].x + b * s[i].y > 0) num++; 28 if(a * s[i].x + b * s[i].y == 0) break; 29 } 30 if(i == 2 * n && num == n) 31 { 32 flag = 1; 33 break; 34 } 35 } 36 if(flag) break; 37 } 38 printf("%d %d\n",a,b); 39 } 40 41 return 0; 42 }