稳定的凸包满足:在加新点使凸包扩大时,新凸包无法包含原来的所有顶点
换句话说,一个稳定的凸包的每一条边上都有至少三个顶点
题目数据比较水,没有所有点共线的特判(非稳定),我也就懒得写了
//#include<bits/stdc++.h>
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<stdio.h>
#include<algorithm>
#include<queue>
#include<string.h>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<vector>
#include<iomanip>
using namespace std; const double pi=acos(-1.0);
#define ll long long
#define pb push_back#define sqr(a) ((a)*(a))
#define dis(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))const double eps=1e-6;
const int maxn=1e3+56;
const int inf=0x3f3f3f3f;int n;
int tot; //凸包上点数struct Point{double x,y;Point(){}Point(double x,double y):x(x),y(y){}
}point[maxn],vertex[maxn];bool cmp(Point a,Point b){return(a.y<b.y||(a.y== b.y && a.x<b.x));
}double xmult(Point p1,Point p2,Point p3){ //p3p1,p3p2的夹角测试return ( (p1.x-p3.x)*(p2.y-p3.y)-(p1.y-p3.y)*(p2.x-p3.x) );
} //正表示p1在p2的顺时针方向int Andrew(){ //返回凸包顶点数sort(point,point+n,cmp);int top=1;vertex[0]=point[0];vertex[1]=point[1];for(int i=2;i<n;i++){while(top && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;vertex[++top]=point[i];}int len=top;vertex[++top]=point[n-2];for(int i=n-3;i>=0;i--){while(top!=len && xmult(point[i],vertex[top],vertex[top-1])>eps)top--;vertex[++top]=point[i];}return top;
}bool judge(int n){ //判凸包稳定for(int i=1;i<n;i++){if(fabs(xmult(vertex[i],vertex[i+1],vertex[i-1]))>eps&&fabs(xmult(vertex[i],vertex[i+1],vertex[(i+2)%(n)]))>eps){return 0;}}return 1;
}int main(){int T;scanf("%d",&T);while(T--){scanf("%d",&n);for(int i=0;i<n;i++){scanf("%lf%lf",&point[i].x,&point[i].y);}tot=Andrew();if(tot<6){printf("NO\n");continue;}if(judge(tot))printf("YES\n");else printf("NO\n");}
}