zoj 1010

# 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

以后要注意!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值