#include <iostream>
#include <stdio.h>
#include <string.h>
#include <cmath>
using namespace std;
struct point
{
int x,y;
friend point operator-(const point &a, const point &b)
{
point c;
c.x = a.x - b.x;
c.y = a.y - b.y;
return c;
}
friend int operator*(const point&a, const point &b)
{
return (a.x*b.y - b.x*a.y);
}
}p[10000],p1[10000];
int main()
{
int n;
int flag1, flag2,f;
while(scanf("%d",&n),n)
{
flag1 = flag2 = f = 0;
for( int i = 0; i<n; i++)
{
scanf("%d%d",&p[i].x ,&p[i].y);
if( i > 0 )
p1[i-1] = p[i] - p[i-1];
}
p1[n-1] = p[0] - p[n-1];
for( int i = 1; i < n; i++)
{
if( i == 0)
flag1 = flag2 = p1[i]*p1[i-1];
else
flag2 = p1[i-1]*p1[i];
if((flag1 >= 0 && flag2 >=0) || (flag1 <=0 && flag2 <=0))
f = true;
else
{
f = false;
break;
}
flag1 = flag2;
}
if(f)
{
flag2 = p1[n-1]*p1[0];
if((flag1 >= 0 && flag2 >=0) || (flag1 <=0 && flag2 <=0))
cout<<"convex"<<endl;
else
f = false;
}
if(!f)
cout<<"concave"<<endl;
}
return 0;
}
看到别人的代码后觉得自己的恶心
#include <stdio.h>
struct
{
int x;
int y;
}a[50];
int mu(int x0,int x1,int x2)
{
return (a[x2].x-a[x0].x)*(a[x1].y-a[x0].y)-(a[x1].x-a[x0].x)*(a[x2].y-a[x0].y);
}
int main ()
{
int n,i,t;
while (scanf("%d",&n)!=EOF)
{
if (n==0) return 0;
t=0;
for (i=0;i<n;i++)
scanf("%d %d",&a[i].x,&a[i].y);
a[n].x=a[0].x;
a[n].y=a[0].y;
a[n+1].x=a[1].x;
a[n+1].y=a[1].y;
for (i=0;i<n;i++)
if (mu(i,i+1,i+2)>0) {t=1;break;}
if (t) printf ("concave\n");
else printf ("convex\n");
}
return 0;
}