Uva 10167
从题目来看,数据量要求不是那么大,对于方法,显然的方法就是简单枚举,经过实际的运算,这样的数据量还是可以的
#include <stdio.h>
#define N 50 * 2 + 1
int x[N], y[N];
int a, b, n;
void split(void);
int main(void)
{
freopen("in.txt", "r", stdin);
while(scanf("%d", &n)) {
if(n == 0) break;
for(int i = 0; i < 2 * n; i++) {
scanf("%d%d", &x[i], &y[i]);
}
split();
}
return 0;
}
int succeed(void)
{
int up = 0, down = 0;
int temp;
for(int i = 0; i < 2 * n; i++) {
if ((temp = (a * x[i] + b * y[i])) == 0)
return 0;
else if (temp > 0)
up++;
else down++;
}
if(up == down) {
printf("%d %d\n", a, b);
return 1;
}
else return 0;
}
void split(void)
{
a = 0; b = 1;
if (succeed()) {
return;
}
a = 1; b = 0;
if (succeed()) {
return;
}
for(a = 1; a <= 500; a++) {
for(b = -500; b <= 500; b++) {
if (succeed())
return;
}
}
}