POJ1228-Grandpa's Estate

Grandpa's Estate
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 10651 Accepted: 2891

Description

Being the only living descendant of his grandfather, Kamran the Believer inherited all of the grandpa's belongings. The most valuable one was a piece of convex polygon shaped farm in the grandpa's birth village. The farm was originally separated from the neighboring farms by a thick rope hooked to some spikes (big nails) placed on the boundary of the polygon. But, when Kamran went to visit his farm, he noticed that the rope and some spikes are missing. Your task is to write a program to help Kamran decide whether the boundary of his farm can be exactly determined only by the remaining spikes.

Input

The first line of the input file contains a single integer t (1 <= t <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains an integer n (1 <= n <= 1000) which is the number of remaining spikes. Next, there are n lines, one line per spike, each containing a pair of integers which are x and y coordinates of the spike.

Output

There should be one output line per test case containing YES or NO depending on whether the boundary of the farm can be uniquely determined from the input.

Sample Input

1
6 
0 0
1 2
3 4
2 0
2 4 
5 0

Sample Output

NO
//AC代码
 
 
要想让一个凸包稳定,当且仅当凸包上任意一条边有3个以上的木桩(包括端点)
证明:
/*
题意:给你一个凸多边形,问你这个凸多边形是不是稳定凸包
*/

#include<iostream>
#include<queue>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iomanip>
#include<map>
#include<cstdlib>
#include<cmath>
const double eps=1e-8;
const double PI=3.1415926;
const int Max=1001;
#define zero(x) (((x)>0?(x):-(x))<eps)
using namespace std;
int sign(double x)
{
    return (x>eps)-(x<-eps);
}
typedef struct Node
{
    double x;
    double y;
}point;
point list[Max],stack[Max];
int mark[Max];
int n;
int top;
double xmult(point p0,point p1,point p2)
{
	return(p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
int dots_inline(point p1,point p2,point p3)//判断三点是否共线
{
    int x=sign(xmult(p1,p2,p3));
    if(x==0)
    return true;
    else
    return false;
}
double Distance(point p1,point p2)// 返回两点之间欧氏距离
{
	return( sqrt( (p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y) ) );
}
bool cmp(point p1,point p2)
{
    double temp;
    temp=xmult(list[0],p1,p2);
    if(temp>0)
        return true;
    if(temp==0&&(Distance(list[0],p1)<Distance(list[0],p2)))
        return true;
    return false;
}

void convex_hull()//凸包模板
{
    int i;
    for(i=1;i<n;i++)
    {
        if((list[i].y<list[0].y)||(list[i].y==list[0].y&&list[i].x<list[0].x))
            swap(list[0],list[i]);
    }
    sort(list+1,list+n,cmp);
    top=1;
    stack[0]=list[0];
    stack[1]=list[1];
    for(i=2;i<n;i++)
    {
        while(top>=1&&xmult(stack[top-1],stack[top],list[i])<=0)
        top--;
        top++;
        stack[top]=list[i];
    }
}
int main()
{
    int m,i,j,p,num,q;
    int T;
    double yy;
    //freopen("D:\\in.txt","r",stdin);
    cin>>T;
    while(T--)
    {
        cin>>n;
        for(i=0;i<n;i++)
        {
            cin>>list[i].x>>list[i].y;
        }
        if(n==1||n==2)
        {
            //cout<<"000"<<endl;
            cout<<"NO"<<endl;
            continue;
        }
        num=0;
        convex_hull();
        for(i=0;i<=top;i++)
        {
           // cout<<stack[i].x<<" "<<stack[i].y<<endl;
            for(j=0;j<n;j++)
            {
                if(stack[i].x==list[j].x&&stack[i].y==list[j].y)
                {
                    mark[num++]=j;
                    break;
                }
            }
        }
        p=0;
        for(i=2;i<n;i++)
        {
            if(dots_inline(list[i-2],list[i-1],list[i]))
            {
                p+=1;
            }
        }
        if(p==(n-2))
        {
            //cout<<"111"<<endl;
            cout<<"NO"<<endl;
            continue;
        }
        q=0;
        //cout<<"top:"<<top<<endl;
        mark[num++]=0;
        //for(i=0;i<num;i++)
        //{
        //    cout<<mark[i]<<endl;
        //}
        for(i=1;i<num;i++)
        {
            p=0;
            for(j=0;j<n;j++)
            {
                if((mark[i-1]!=j)&&(mark[i]!=j))
                {
                    //cout<<mark[i-1]<<" "<<mark[i]<<" "<<j<<" asdasd"<<endl;
                    int d1=mark[i-1];
                    int d2=mark[i];
                    //cout<<list[d2].x<<" "<<list[d2].y<<endl;
                    //cout<<stack[d1].x<<" "<<stack[d1].y<<" "<<stack[d2].x<<" "<<stack[d2].y<<" "<<list[j].x<<" "<<list[j].y<<endl;
                    if(dots_inline(list[d1],list[d2],list[j]))
                    {
                        //cout<<mark[i-1]<<" "<<mark[i]<<" OK"<<endl;
                        p=1;
                        break;
                    }
                }
            }
            if(p==0)
            {
                q=1;
                break;
            }

        }
        if(q)
            cout<<"NO"<<endl;
        else
            cout<<"YES"<<endl;
    }
    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值