题意:给出一些凸包上的点 这些点均是凸包上的点 判断该凸包是否为稳定凸包 即是否每条边上是否至少有三个点 改下凸包的模板即可
#include <iostream>
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "math.h"
#include "algorithm"
#include <queue>
using namespace std;
#define modulo 1000000007
const double eps=1e-8;
int n,top;
double ansx,ansy;
struct ed {
double x,y;
}point[1010],sta[1010];
double mult(double x1,double y1,double x2,double y2,double x3,double y3)
{
return (x1-x3)*(y2-y3)-(y1-y3)*(x2-x3);
}
int sgn(double x)
{
if(fabs(x)<eps) return 0;
if(x<0) return -1;
else return 1;
}
double dis(ed a,ed b)
{
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int cmp(const void *a,const void *b)
{
ed c=*(ed *)a;
ed d=*(ed *)b;
double k=mult(c.x,c.y,d.x,d.y,point[0].x,point[0].y);
if(k<0||(!k&&dis(c,point[0])>dis(d,point[0]))) return 1;
else return -1;
}
void convex()
{
for(int i=1;i<n;i++)
{
ed temp;
if(point[i].y<point[0].y||(point[i].y==point[0].y&&point[i].x<point[0].x)){
temp=point[i];
point[i]=point[0];
point[0]=temp;
}
}
qsort(point+1,n-1,sizeof(point[0]),cmp);
sta[0]=point[0];sta[1]=point[1];
top=1;
for(int i=2;i<n;i++)
{
while(top>=1&&mult(sta[top].x,sta[top].y,point[i].x,point[i].y,sta[top-1].x,sta[top-1].y)<0) top--;
top++;
sta[top]=point[i];
}
}
bool judge()
{
for(int i=1;i<top;i++)
if(mult(sta[i].x,sta[i].y,sta[i+1].x,sta[i+1].y,sta[i-1].x,sta[i-1].y)!=0&&mult(sta[i+1].x,sta[i+1].y,sta[i+2].x,sta[i+2].y,sta[i].x,sta[i].y)!=0)
return false;
return true;
}
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%lf%lf",&point[i].x,&point[i].y);
if(n<6) printf("NO\n");
else {
convex();
if(judge()) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
POJ 1228 稳定凸包问题
最新推荐文章于 2021-02-17 19:02:18 发布