思路:简单枚举
AC代码:
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; int x[105], y[105]; int main() { int A, B, N; while(scanf("%d", &N), N) { for(int i = 0; i < 2 * N; i++) { scanf("%d %d", &x[i], &y[i]); } int flag = 0; for(A = -500; A <= 500 && !flag; A++) { for(B = -500; B <= 500 && !flag; B++) { if(A || B) { int c1 = 0, c2 = 0; for(int i = 0; i < 2 * N; i++) { if(x[i] * A + y[i] * B > 0) c1 ++; else if(x[i] * A + y[i] * B < 0) c2 ++; if(c1 == c2 && c1 == N) { printf("%d %d\n", A, B); flag = 1; } } } } } } return 0; }
UVA - 10167 - Birthday Cake (简单枚举)
原文地址:http://blog.csdn.net/u014355480/article/details/44464845