D - Grandpa's Estate POJ - 1228(稳定凸包)

D - Grandpa’s Estate POJ - 1228

当凸包上存在一条边上的点只有端点两个点的时候,这个凸包不是稳定的,因为它可以在这条边外再引入一个点,构成一个新的凸包。但一旦一条边上存在三个点,那么不可能再找到一个点使它扩展成一个新的凸包,否则构成的新多边形将是凹的。

在这里插入图片描述
在这里插入图片描述

也就是说只要凸包上的每一条边上至少有三个点就是稳定凸包了, 那就直接求凸包然后对凸包上的每条边的检查一次.
但是这里求凸包的方法应该要用Andrew才对, 我不知道为什么别人的Graham_scan也能过, 因为用Graham_scan的话下面这种情形就不能考虑到
在这里插入图片描述
p [ 1 ] , p [ 8 ] , p [ 9 ] p[1],p[8],p[9] p[1],p[8],p[9]共线, 他会把 p [ 8 ] p[8] p[8]弹出再把 p [ 9 ] p[9] p[9]算入凸包里, 这样最后一条边上就只有 p [ 1 ] p[1] p[1] p [ 9 ] p[9] p[9]了, 无法理解为什么能过
代码:

#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
const int MAXN=1e3+10;
const double EPS=1e-8;
const double PI=acos(-1);
inline int sgn(double a){ return a < -EPS ? -1 : a > EPS; }
inline int cmp(double a, double b){ return sgn(a-b); }
long long mod=1e9+7;
int n,m,T;
struct Point;
typedef Point Vector;
struct Point{
    double x,y;
    Point(){}
    Point(double a, double b):x(a),y(b){}
    double len(){return sqrt(x*x+y*y);}
    void read(){scanf("%lf%lf",&x,&y);}
    Point operator+(const Vector v)const{return {x+v.x,y+v.y};}
    Vector operator-(const Point p)const{return {x-p.x,y-p.y};}
    double operator^(const Vector v)const{return x*v.y-y*v.x;}//叉乘
    double operator*(const Vector v)const{return x*v.x+y*v.y;}//点乘
    Vector operator*(const double d)const{return {x*d,y*d};}
    Vector operator/(const double d)const{return {x/d,y/d};}
    bool operator==(const Point p)const{return cmp(x,p.x)==0&&cmp(y,p.y)==0;}
    bool operator<(const Point p)const{if(cmp(x,p.x)==0) return y<p.y;return x<p.x;}
};
Point p[1010],stk[1010];
int Andrew(){
    sort(p+1,p+n+1);
    int len=0;
    for (int i=1;i<=n;i++){
        while (len>1&&sgn((stk[len]-stk[len-1])^(p[i]-stk[len-1]))<0) len--;
        stk[++len]=p[i];
    }
    int k=len;
    for (int i=n-1;i>=1;i--){
        while (len>k&&sgn((stk[len]-stk[len-1])^(p[i]-stk[len-1]))<0) len--;
        stk[++len]=p[i];
    }
    len--;
    return len;
}
void solve(){
    if(n<6){
        printf("NO\n");
        return ;
    }
    int len=Andrew();
    stk[0]=stk[len];
    stk[len+1]=stk[1];
    stk[len+2]=stk[2];
    for(int i=1;i<=len;i++){
        if(sgn((stk[i+2]-stk[i])^(stk[i+1]-stk[i]))==0||
            sgn((stk[i+1]-stk[i-1])^(stk[i]-stk[i-1]))==0)
            continue;
        printf("NO\n");
        return;
    }
    printf("YES\n");
}
void init(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        p[i].read();
}
int main(){
    scanf("%d",&T);
    while(T--){
        init();
        solve();
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值