题意:判断是否为凸多边形,是就输出No,不是输出Yes
分析:采用凸包解决,用Graham扫描算法,就出来了
#include <iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
#define N 105
#define EPS 1e-3
struct point
{
double x,y;
point(double x,double y):x(x),y(y){}
point(){}
bool operator< (const point &s)const
{
return x<s.x||(x==s.x&&y<s.y);
}
double det(point a)
{
return x*a.y-y*a.x;
}
point operator-(point a)
{
return point(x-a.x,y-a.y);
}
point operator +(point a)
{
return point(x+a.x,y+a.y);
}
point operator *(double s)
{
return point(x*s,y*s);
}
point operator /(double s)
{
return point(x/s,y/s);
}
};
point p[N],res[N];
int n,k;
int main()
{
while(~scanf("%d",&n)&&n)
{
for(int i=0;i<n;i++)
{
scanf("%lf%lf",&p[i].x,&p[i].y);
}
sort(p,p+n);
k=0;
for(int i=0;i<n;i++)
{
while(k>1&&(res[k-1]-res[k-2]).det(p[i]-res[k-2])<0)
k--;
res[k++]=p[i];
}
int t=k;
for(int i=n-2;i>=0;i--)
{
while(k>t&&(res[k-1]-res[k-2]).det(p[i]-res[k-2])<0)
k--;
res[k++]=p[i];
}
if(k==n+1)
{
printf("No\n");
}
else
printf("Yes\n");
}
return 0;
}