题意:给你一个凸包的所有的点,求看其是否能组成唯一的凸包
思路:组成唯一的凸包,那么他的每一条边至少有三个点,因为如果有有两个点,那么可以再加一个点使得凸包扩大,所以每条边至少三个点。
这就和以前组成的凸包不太一样的,以前组凸包有可能没有考虑其边界上有点,因为这对面积没有什么影响,但是这题有影响,所以再求凸包的时候不能要边界上的点,等于说是求得了真正的凸包,每条边只有两个端点,然后枚举每条线段看是否有点在上面,只要有一条边不含三个以上的点,那么这个凸包就是不确定的。
这点还要注意是:
求凸包是3个点以上,并且三个点不在一条直线上,所以当三点共线或者不到三个点的时候都不能组成凸包
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
using namespace std;
struct Point
{
double x,y;
double v,L;
Point(double x = 0,double y = 0) : x(x),y(y) {}
};
typedef Point Vector;
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 p) { return Vector(a.x*p,a.y*p) ;}
Vector operator / (Vector a,double p) { return Vector(a.x/p,a.y/p) ;}
const double eps = 1e-9;
const double PI = acos(-1.0);
double Dot(Vector a,Vector b) { return a.x*b.x + a.y*b.y ;}
double Length(Vector a) { return sqrt(Dot(a,a)) ;}
double Cross(Vector a,Vector b) { return a.x*b.y - a.y*b.x ;}
int dcmp(double x)
{
if(fabs(x) < eps) return 0;
else return x < 0 ? -1 : 1;
}
bool operator < (Point a,Point b) { return a.x < b.x || (a.x == b.x && a.y < b.y) ;}
bool operator == ( Point a, Point b) { return dcmp(a.x-b.x) == 0 && dcmp(a.y-b.y) == 0 ;}
double Angle(Vector a,Vector b) { return acos( Dot(a,b) / Length(a) / Length(b) ) ;}
double Area(Point a,Point b,Point c) { return fabs(Cross(b-a,c-a))/2 ;}
Vector Rotate(Vector a,double rad) { return Vector(a.x*cos(rad) - a.y*sin(rad),a.x*sin(rad) + a.y*cos(rad) );}
Vector Normal(Vector a)
{
double L = Length(a);
return Vector(-a.y/L,a.x/L);
}
Point GetLineIntersection(Point p,Vector v,Point q,Vector w)
{
Vector u = p - q;
double t = Cross(w,u) / Cross(v,w);
return p + v*t;
}
bool SegmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{
double c1 = Cross(a2-a1,b1-a1) ,c2 = Cross(a2-a1,b2-a1),c3 = Cross(b2-b1,a1-b1),c4 = Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2) < 0 && dcmp(c3) *dcmp(c3) < 0;
}
bool OnSengment(Point p,Point a,Point b)
{
return dcmp(Cross(p-a,b-a)) == 0 && dcmp(Dot(a-p,b-p) < 0);
}
double PolyArea(Point *p,int n)
{
double area = 0;
int i;
for(i = 0; i < n; i++)
{
area += Cross(p[i]-p[0],p[i+1]-p[0]);
}
return area/2;
}
int Chell(Point *p,int n,Point *ch)
{
int i,m = 0;
sort(p,p+n);
for(i = 0; i < n;i++)
{
while(m > 1 && Cross( ch[m-1] - ch[m-2],p[i] - ch[m-2]) <= 0) m--;
ch[m++] = p[i];
}
int k = m;
for(i = n-2; i >= 0; i--)
{
while(m > k && Cross(ch[m-1] - ch[m-2],p[i] - ch[m-2] ) <= 0) m--;
ch[m++] = p[i];
}
if(n > 1) m--;
return m;
}
Point p[1005];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
Point ch[1005];
int temp = Chell(p,n,ch);
int i,j,flag = 0;
if(temp < 3)
{
printf("NO\n");continue;
}
for( i = 0; i < temp; i++)
{
for( j = 0; j < n; j++)
{
if(OnSengment(p[j],ch[i],ch[(i+1)%temp]))
{
break;
}
}
if(j >= n)
{
flag = 1;break;
}
}
if(flag)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}