# include <stdio.h>
# include <string.h>
# define eps 1e-6
# include <math.h>
struct node
{
double x,y;
}vex[1009];
int sign(double x)
{
if(x<-eps) return -1;
if(x>eps) return 1;
return 0;
}
int zero(double x)
{
if(x<eps&&x>-eps) return 1;
return 0;
}
int on(node a,node b,node c)
{
double maxx=a.x>b.x?a.x:b.x;
double minx=a.x>b.x?b.x:a.x;
double maxy=a.y>b.y?a.y:b.y;
double miny=a.y>b.y?b.y:a.y;
if(c.x<=maxx&&c.x>=minx&&c.y<=maxy&&c.y>=miny)
return 1;
else
return 0;
}
double cross(node a,node b,node c)
{
return (c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);
}
int inser(node a,node b,node c,node d)
{
double d1=cross(a,b,c);
double d2=cross(a,b,d);
double d3=cross(c,d,a);
double d4=cross(c,d,b);
if(sign(d1*d2)==-1&&sign(d3*d4)==-1)
return 1;
if(zero(d1)&&on(a,b,c))
return 1;
if(zero(d2)&&on(a,b,d))
return 1;
if(zero(d3)&&on(c,d,a))
return 1;
if(zero(d4)&&on(c,d,b))
return 1;
return 0;
}
int is(int n)
{
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
if(j!=i+1&&(j+1)%n!=i&&inser(vex[i],vex[i+1],vex[j],vex[j+1]))
{
return 0;
}
return 1;
}
double area(int n)
{
double sum=0;
for(int i=1; i<n; i++)
{
sum+=cross(vex[0],vex[i],vex[i+1])/2.0;
}
return fabs(sum);
}
int main ()
{
int n,cas=1,mark=0;
while(scanf("%d",&n)!=EOF)
{
if(n==0) break;
if(mark)
printf("\n");
for(int i=0;i<n;i++)
scanf("%lf%lf",&vex[i].x,&vex[i].y);
printf("Figure %d: ",cas++);
if(n<3)
{
printf("Impossible\n");
mark=1;
continue;
}
vex[n]=vex[0];
if(is(n))
printf("%.2lf\n",area(n));
else
printf("Impossible\n");
mark=1;
}
return 0;
}
这题把我折磨了N天外加一个下午加一个晚上 终于看出来哪错了 注意 注意 第20行 判断短点在线段上的时候 之前总是很懒 不想写y的判断 现在终于写上了才过的 hiahiahia
以后要注意!!!