题意:一个老头得到了一个破旧的农场,农场由大铁钉和绳子围成,给出当前的钉子的坐标,是否能确定农场的规模
就是一个稳定的凸包问题,结论:要想让一个凸包稳定,当且仅当凸包上任意一条边有3个以上的木桩(包括端点)
首先建立起凸包,依次枚举凸包上两定点之间是否有其他的点在这条线上(关键为叉积的运用)
#include<stdio.h>
#include<iostream>
using namespace std;
#include<algorithm>
int t,n;
struct point
{
int x,y;
}p[50005],ch[50005];
bool cmp(point a,point b)
{
if(a.x!=b.x)return a.x<b.x;
else return a.y<b.y;
}
int judge(point a,point b,point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int ass(point a,point b)
{
return (a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y);
}
int panduan(point a,point b)
{
int num=0;
for(int i=0;i<n;i++)
{
if(judge(a,p[i],b)==0)num++;
}
if(num>=3)return 1;
else return 0;
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
if(n<6){printf("NO\n");continue;}
sort(p,p+n,cmp);
int top=0;
for(int i=0;i<n;i++)
{
while(top>1&&judge(ch[top-2],ch[top-1],p[i])<=0)top--;
ch[top++]=p[i];
}
int k=top;
for(int i=n-2;i>=0;i--)
{
while(top>k&&judge(ch[top-2],ch[top-1],p[i])<=0)top--;
ch[top++]=p[i];
}
if(n>1)top--;
int c;
for(c=1;c<top;c++)
if(!panduan(ch[c],ch[c-1]))
break;
if(c<top||!panduan(ch[0],ch[top-1]))printf("NO\n");
else printf("YES\n");
}
}