poj 1228
2013-08-19 18:45
134 查看
做了一个晚上 的题目,晕了
View Code
View Code
#include<stdio.h> #include<string.h> #include<math.h> #include<algorithm> using namespace std; const double eps=1e-9; #define zero(x) (((x)>0? (x):-(x))<eps) struct point{ double x,y; }a[1010]; int n,s[1010]; int top; int cmp(point a,point b) { if(a.y==b.y) return a.x<b.x; return a.y<b.y; } double cross(point a,point b,point c) { return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y); } int dbcmp(double d) { if(zero(d)) return 0; else return d>0?1:-1; } void tubao() { int i,temp; sort(a,a+n,cmp); top=-1; s[++top]=0; s[++top]=1; for(i=2;i<n;i++) { while(top>=1&&dbcmp(cross(a[s[top-1]],a[i],a[s[top]]))>=0) top--; s[++top]=i; } temp=top; s[++top]=n-2; for(i=n-3;i>=0;i--) { while(top>=temp+1&&dbcmp(cross(a[s[top-1]],a[i],a[s[top]]))>=0) top--; s[++top]=i; } }//最后一点和第一点是一样的,即重复的 bool dot_in_line(point a,point b,point c)//判断a是否在线段bc上 { return zero(cross(a,b,c))&&(a.x-b.x)*(a.x-c.x)<eps&&(a.y-b.y)*(a.y-c.y)<eps; } bool check(int n) { int i,j,count; if(n<=5) return false; if(top==1) return false; for(i=0;i<top;i++) { count=0; for(j=0;j<n;j++) { if(dot_in_line(a[j],a[s[i]],a[s[i+1]])) { count++; } } if(count<3) return false; } return true; } int main() { int t,i,j,flag; scanf("%d",&t); while(t--) { scanf("%d",&n); for(i=0;i<n;i++) scanf("%lf%lf",&a[i].x,&a[i].y); tubao(); if(check(n)) printf("YES\n"); else printf("NO\n"); } return 0; }
相关文章推荐
- poj 1228(凸包)
- POJ 1228:Grandpa's Estate (稳定凸包)
- POJ 1228 Grandpa's Estate -
- poj 1228 Grandpa's Estate (稳定凸包问题)
- POJ 1228 Grandpa's Estate 计算凸包+判断点在线段上
- POJ 1228 Grandpa's Estate
- poj 1228 Grandpa's Estate
- POJ 1228 Grandpa's Estate
- POJ 1228 || Grandpa's Estate(凸包andrew算法
- POJ 1228 Grandpa's Estate
- poj 1228 Grandpa's Estate
- POJ 1228 Grandpa's Estate(凸包)
- POJ 1228 Grandpa's Estate (求稳定凸包)
- poj 1228 Grandpa's Estate
- POJ 1228 Grandpa's Estate(给定凸包上的一部分顶点 判断表示的凸包是否唯一)
- POJ 1228 Grandpa's Estate(判断是否稳定凸包)
- POJ 1228 稳定凸包
- zoj 1377 || poj 1228 Grandpa's Estate (看了题解,待解决)
- POJ 1228 Grandpa's Estate(凸包)
- POJ 1228 Grandpa's Estate