POJ 1228 Grandpa's Estate(凸包)

题意:没看懂题意,在DISCUSS找到的,,判断一个凸包,且每两个凸点间的直线上有一个点。。

思路:找两个凸包一个包括非顶点的边点,另一个不包含,比较一下两个凸包。。


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
using namespace std;
struct cpoint{
    double x,y;
    bool operator<(const cpoint a)const{
        return y<a.y||(y==a.y&&x<a.x);
    }
    bool operator==(const cpoint a)const{
        return a.x==x&&a.y==y;
    }
    void get(){scanf("%lf%lf",&x,&y);}
};
double x_mult(cpoint a,cpoint b,cpoint c){
    return (a.x-c.x)*(b.y-c.y)-(a.y-c.y)*(b.x-c.x);
}
cpoint p[1009],ans1[1009],ans2[1009];
int granham(cpoint p[],int s,cpoint r[],double EPS)
{
    int i,len,top = 1;
    sort(p,p+s);
    r[0] = p[0],r[1] = p[1];
    if(s<3) return s;
    for(i=2;i<s;i++){
        while(top&&x_mult(p[i],r[top],r[top-1])>EPS) top--;
        r[++top] = p[i];
    }
    len = top;r[++top] = p[s-2];
    for(i=s-3;i>=0;i--){
        while(top!=len&&x_mult(p[i],r[top],r[top-1])>EPS) top--;
        r[++top] = p[i];
    }
    return top;
}
int main()
{
    freopen("in.txt","r",stdin);
    int cas,n;
    scanf("%d",&cas);
    while(cas--)
    {
        scanf("%d",&n);
        for(int i=0;i<n;i++) p[i].get();
        if(n<=5){
            printf("NO\n");continue;
        }
        int k1=granham(p,n,ans1,1e-6);
        int k2=granham(p,n,ans2,-1e-6);
        int k = 1;bool fin = false;
        for(int i=1;i<=k1;i++)
        if(ans1[i]==ans2[k]){
            if(ans1[i-1]==ans2[k-1]) fin = true;
            else k++;
        }
        if(fin) printf("NO\n");
        else printf("YES\n");
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值