poj 1228

做了一个晚上 的题目,晕了

View Code
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
const double eps=1e-9;
#define zero(x) (((x)>0? (x):-(x))<eps)
struct point{
double x,y;
}a[1010];
int n,s[1010];
int top;
int cmp(point a,point b)
{
if(a.y==b.y)
return a.x<b.x;
return a.y<b.y;
}
double cross(point a,point b,point c)
{
return (b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y);
}
int dbcmp(double d)
{
if(zero(d)) return 0;
else return d>0?1:-1;
}
void tubao()
{
int i,temp;
sort(a,a+n,cmp);
top=-1;
s[++top]=0;
s[++top]=1;
for(i=2;i<n;i++)
{
while(top>=1&&dbcmp(cross(a[s[top-1]],a[i],a[s[top]]))>=0)
top--;
s[++top]=i;
}
temp=top;
s[++top]=n-2;
for(i=n-3;i>=0;i--)
{
while(top>=temp+1&&dbcmp(cross(a[s[top-1]],a[i],a[s[top]]))>=0)
top--;
s[++top]=i;
}
}//最后一点和第一点是一样的,即重复的
bool dot_in_line(point a,point b,point c)//判断a是否在线段bc上
{
return zero(cross(a,b,c))&&(a.x-b.x)*(a.x-c.x)<eps&&(a.y-b.y)*(a.y-c.y)<eps;
}
bool check(int n)
{
int i,j,count;
if(n<=5) return false;
if(top==1) return false;
for(i=0;i<top;i++)
{
count=0;
for(j=0;j<n;j++)
{
if(dot_in_line(a[j],a[s[i]],a[s[i+1]]))
{
count++;
}
}
if(count<3) return false;
}
return true;
}
int main()
{
int t,i,j,flag;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf%lf",&a[i].x,&a[i].y);
tubao();
if(check(n)) printf("YES\n");
else printf("NO\n");
}
return 0;
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值