"No regrets."

# [POJ1228]Grandpa's Estate（凸包）

• 至少有三个顶点
• 每条边上至少有三个点

## 代码

#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
#define N 1005

const double eps=1e-9;
int dcmp(double x)
{
if (x<=eps&&x>=-eps) return 0;
return (x>0)?1:-1;
}
struct Vector
{
double x,y;
Vector(double X=0,double Y=0)
{
x=X,y=Y;
}
bool operator < (const Vector &a) const
{
return x<a.x||(x==a.x&&y<a.y);
}
};
typedef Vector Point;
Vector operator - (Vector A,Vector B) {return Vector(A.x-B.x,A.y-B.y);}

int T,n,cnt,top;
double x,y;
Point p[N],stack[N];
int flag[N];
bool ans;

void clear()
{
n=top=cnt=0;
x=y=0;
memset(flag,0,sizeof(flag));
}
double Cross(Vector A,Vector B)
{
return A.x*B.y-A.y*B.x;
}
void Graham()
{
sort(p+1,p+n+1);
for (int i=1;i<=n;++i)
{
while (top>1&&dcmp(Cross(stack[top]-stack[top-1],p[i]-stack[top-1]))<0)
--top;
stack[++top]=p[i];
}
int k=top;
for (int i=n-1;i>=1;--i)
{
while (top>k&&dcmp(Cross(stack[top]-stack[top-1],p[i]-stack[top-1]))<0)
--top;
stack[++top]=p[i];
}
if (n>1) --top;
}
int main()
{
scanf("%d",&T);
while (T--)
{
clear();
scanf("%d",&n);
for (int i=1;i<=n;++i)
{
scanf("%lf%lf",&x,&y);
p[i]=Point(x,y);
}
Graham();
for (int i=2;i<=top+1;++i)
if (dcmp(Cross(stack[(i-1)%top+1]-stack[i%top+1],stack[(i+1)%top+1]-stack[i%top+1]))==0)
++flag[(i-1)%top+1],++flag[(i+1)%top+1];
else ++cnt;
ans=(cnt>=3);
for (int i=2;i<=top+1;++i)
if (dcmp(Cross(stack[(i-1)%top+1]-stack[i%top+1],stack[(i+1)%top+1]-stack[i%top+1]))!=0)
ans&=(flag[i%top+1]>=2);
if (!ans) puts("NO");
else puts("YES");
}
}

#### poj1228 - Grandpa's Estate

2012-08-27 10:18:58

#### poj1228 Grandpa's Estate(凸包)

2016-09-27 14:30:58

#### poj1228 Grandpa's Estate 凸包

2015-08-07 20:49:12

#### POJ1228 Grandpa's Estate

2018-01-25 14:34:51

#### Poj1228 Grandpa's Estate

2016-06-01 20:40:29

#### POJ1228——Grandpa's Estate（计算几何，凸包）

2016-07-29 10:09:32

#### POJ1228 Grandpa's Estate 还是凸包

2011-08-02 00:00:25

#### [POJ1228]Grandpa's Estate（计算几何-凸包）

2018-01-18 20:39:36

#### 【稳定凸包】poj1228 Grandpa's Estate

2017-07-10 22:45:44

#### poj1228 Grandpa's Estate【凸包稳定性判断】

2017-04-19 13:04:55