开始一看,以为还是极角排序加扫描线呢。后来发现不好弄啊,如果有很多位置,那么我扫到一个cherries 但是正好在满足题意的边界上,我随便加个eps应该就行了吧?
后来再一看 = =。。。A B要求是整数,而且范围在-500到500,这个好办了。直接枚举每个 A B ,然后判断是否满足题意即可。
注意处理cherries 在线上的状况。
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define BUG puts("here!!!")
#define STOP system("pause")
using namespace std;
const int MAX = 100;
struct point {double x,y;};
point p[MAX];
double t[MAX];
void solve(int n,int &a, int &b)
{
for(int i=-500; i<=500; i++)
for(int k=-500; k<=500; k++)
{
if( i == k && k == 0 ) continue;
int cnt = 0;
for(int j=0; j<n; j++)
{
if( i*p[j].x + k*p[j].y == 0 )
{
cnt = 0;
break;
}
if( i*p[j].x + k*p[j].y > 0 )
cnt++;
}
if( cnt == n/2 )
{
a = i;
b = k;
return ;
}
}
}
int main()
{
int n;
while( ~scanf("%d", &n) && n )
{
int sum = n;
n *= 2;
for(int i=0; i<n; i++)
scanf("%lf%lf", &p[i].x, &p[i].y);
int a,b;
solve(n, a, b);
printf("%d %d\n",a, b);
}
return 0;
}