此题为小白书暴力求解法的训练参考
题目链接 http://acm.hust.edu.cn/vjudge/problem/19398
解题思路
A、B从-500枚举到500
注意 直线上不能出现点
代码
#include<stdio.h> const int maxLen = 101; typedef struct point { int x, y; }Point; Point setP[maxLen]; void Search(int n) { int A, B; for(A=-500; A<=500; A++) { for(B=-500; B<=500; B++) { int count1 = 0; int count2 = 0; for(int i=0; i<2*n; i++) { int res = A*setP[i].x+B*setP[i].y; if(res > 0) count1++; if(res < 0) count2++; } if(count1 == n && count2 == n) { printf("%d %d\n", A, B); return ; } } } } int main() { int n; scanf("%d", &n); while(n != 0) { int x, y; for(int i=0; i<2*n; i++) { Point temp; scanf("%d%d", &x, &y); temp.x=x; temp.y=y; setP[i] = temp; } Search(n); scanf("%d", &n); } return 0; }
时间: 2024-12-24 21:51:01