# Poj1228 Grandpa's Estate

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 1005;
#define EPS 1e-6
#define INF 1e9
struct point {
double x,y;
point(){}
point(double _x,double _y):x(_x),y(_y){}
point operator - (const point &a) {return point(x-a.x,y-a.y);}
bool operator != (const point &a) {return x!=a.x || y!=a.y;}
bool operator == (const point &a) {return x==a.x && y==a.y;}
};
double multi(point a,point b) {return a.x*b.y - a.y*b.x;}
double dis(point a,point b) {point c=a-b;return sqrt(1.0*c.x*c.x+1.0*c.y*c.y);}
bool cmp(point a,point b) {return a.x < b.x || (a.x==b.x && a.y < b.y);}
point P[maxn],hull[maxn];
int N,cnt=0;
double s[maxn];
void quickhull(int L,int R,point a,point b) {
int x = L,i=L-1,j=R+1;
for(int k = L; k <= R; k++) if( s[k]-s[x] > EPS || ( fabs(s[x]-s[k])<EPS && cmp(P[x],P[k]))) x=k;
point y = P[x];
for(int k = L; k <= R; k++) {
s[++i] = multi(a-P[k],y-P[k]);
if( s[i] > EPS) swap(P[i],P[k]); else i--;
}
for(int k = R; k >= L; k--) {
s[--j] = multi(y-P[k],b-P[k]);
if( s[j] > EPS) swap(P[j],P[k]); else j++;
}
if( L <= i ) quickhull(L,i,a,y);
hull[++cnt] = y;
if( j <= R ) quickhull(j,R,y,b);
}
bool judge(point a,point b,point k) {
return fabs(multi(k-a,b-a)) < EPS;
}
int main() {
int T;
for(scanf("%d",&T);T;T--) {
scanf("%d",&N);
memset(s,0,sizeof s);
P[0] = point(INF,INF); int x = 0;
for(int i = 1; i <= N; i++) {
scanf("%lf%lf",&P[i].x,&P[i].y);
if( cmp(P[i],P[x]) ) x=i;
}
if(N< 5) {puts("NO"); continue;}
swap(P[1],P[x]);

cnt=0;
hull[++cnt] = P[1];
quickhull(2,N,P[1],P[1]);
hull[++cnt] = P[1];
bool fg = 1;
for(int i = 2; i <= cnt; i++) {
point a = hull[i-1];
point b = hull[i];
bool found=0;
for(int j = 1; j <= N; j++){
if(P[j] == a || P[j] == b) continue;
if(judge(a,b,P[j])) {found=1;break;}
}
if( !found ){ fg = 0; break;}
}
puts( fg ? "YES" : "NO");

}
}

• 广告
• 抄袭
• 版权
• 政治
• 色情
• 无意义
• 其他

120