hdu2108 Shape of HDU

//公式:s=(x1-x3)*(y2-y3)-(x2-x3)*(y1-y3)  
//当s>0时,p1,p2,p3三个点呈逆时针  
//当s<0时,p1,p2,p3三个点呈顺时针
#include <stdio.h>

struct point
{
	int x,y;
}p[1002];

int get(int a,int b,int c)
{
	int s;
	s=(p[a].x-p[c].x)*(p[b].y-p[c].y)-(p[b].x-p[c].x)*(p[a].y-p[c].y);
	return s;
}
int main()
{
	int n,ans,i;
	while(scanf("%d",&n)&&n)
	{
		for(i=0;i<n;i++)
			scanf("%d %d",&p[i].x,&p[i].y);
		for (i=0;i<n;i++)
		{
			ans=get(i%n,(i+1)%n,(i+2)%n);
			if(ans<0)
				break;
		}
		if(ans>0)
			printf("convex\n");
		else
			printf("concave\n");
	}
	return 0;
}

你可能感兴趣的:(hdu2108 Shape of HDU)