标签:strong 心情不好 arc uniq false nes ram cto int
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 13112 | Accepted: 3697 |
Description
Input
Output
Sample Input
1 6 0 0 1 2 3 4 2 0 2 4 5 0
Sample Output
NO
Source
题意:输入一个凸包上的点(没有凸包内部的点,要么是凸包顶点,要么是凸包边上的点),判断这个凸包是否稳定。所谓稳
定就是判断能不能在原有凸包上加点,得到一个更大的凸包,并且这个凸包包含原有凸包上的所有点。
就是求凸包时把共线的点也加入凸包然后判断相邻两个连续三个点是不是至少有一个是共线的如果稳定那么必定有一个是共线还有一个特判至少六个点才行哦明白了吧我现在心情不好因为刚刚钥匙串出问题了网络出问题了所以凑合着看吧
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <vector> using namespace std; typedef long long ll; const int N=1005; const double eps=1e-8; const double pi=acos(-1); inline int read(){ char c=getchar();int x=0,f=1; while(c<‘0‘||c>‘9‘){if(c==‘-‘)f=-1; c=getchar();} while(c>=‘0‘&&c<=‘9‘){x=x*10+c-‘0‘; c=getchar();} return x*f; } inline int sgn(double x){ if(abs(x)<eps) return 0; else return x<0?-1:1; } struct Vector{ double x,y; Vector(double a=0,double b=0):x(a),y(b){} bool operator <(const Vector &a)const{ //return x<a.x||(x==a.x&&y<a.y); return sgn(x-a.x)<0||(sgn(x-a.x)==0&&sgn(y-a.y)<0); } }; typedef Vector Point; Vector operator +(Vector a,Vector b){return Vector(a.x+b.x,a.y+b.y);} Vector operator -(Vector a,Vector b){return Vector(a.x-b.x,a.y-b.y);} Vector operator *(Vector a,double b){return Vector(a.x*b,a.y*b);} Vector operator /(Vector a,double b){return Vector(a.x/b,a.y/b);} bool operator ==(Vector a,Vector b){return sgn(a.x-b.x)==0&&sgn(a.y-b.y)==0;} double Dot(Vector a,Vector b){return a.x*b.x+a.y*b.y;} double Cross(Vector a,Vector b){return a.x*b.y-a.y*b.x;} int ConvexHull(Point p[],int n,Point ch[]){ sort(p+1,p+1+n); int m=0; for(int i=1;i<=n;i++){ while(m>1&&sgn(Cross(ch[m]-ch[m-1],p[i]-ch[m-1]))<0) m--; ch[++m]=p[i]; } int k=m; for(int i=n-1;i>=1;i--){ while(m>k&&sgn(Cross(ch[m]-ch[m-1],p[i]-ch[m-1]))<0) m--; ch[++m]=p[i]; } if(n>1) m--; return m; } int n,r,x,y; double ans; Point p[N],ch[N]; bool solve(){ for(int i=2;i<=n;i++) if(sgn(Cross(ch[i]-ch[i-1],ch[i%n+1]-ch[i]))!=0 &&sgn(Cross(ch[i%n+1]-ch[i],ch[(i+1)%n+1]-ch[i%n+1]))!=0) return false; return true; } int main(int argc, const char * argv[]) { int T=read(); while(T--){ n=read(); for(int i=1;i<=n;i++) p[i].x=read(),p[i].y=read(); if(n<6) {puts("NO");continue;} n=ConvexHull(p,n,ch); if(solve()) puts("YES");else puts("NO"); } return 0; }
POJ 1228 Grandpa's Estate [稳定凸包]
标签:strong 心情不好 arc uniq false nes ram cto int
原文地址:http://www.cnblogs.com/candy99/p/6354409.html