hdu 2108 Shape of HDU

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2108
题意:逆时针给你多边形上的点,让你判断这是凸多边形还是凹多边形
解析:就跟凸包的判断一样,直接三个点三个点的叉乘,如果小于零,说明凹多边形

#include 
#include 
#include 
#include 
#include 
#include 
using namespace std;
const int maxn = 1000000+10;
const double eps = 1e-5;
struct point
{
    int x;
    int y;
    point() {}
    point(int _x,int _y)
    {
        x = _x;
        y = _y;
    }
}a[maxn];
int x_mul(point p0,point p1,point p2)
{
    return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
bool judge(int n)
{
    for(int i=0;iif(x_mul(a[i],a[(i+1)%n],a[(i+2)%n])<0)
            return false;
    }
    return true;
}
int main(void)
{
    int n;
    while(~scanf("%d",&n)&&n)
    {
        for(int i=0;iscanf("%d %d",&a[i].x,&a[i].y);
        if(judge(n))
            puts("convex");
        else
            puts("concave");
    }
    return 0;
}

你可能感兴趣的:(ACM,OnlineJudge,HDU,ACM,几何)