fzu 1015

我不知道规律,但是我在草稿纸上摸索的着猜了一下应该是在所形成的面的多少等线的个数+1+交点个数

一发ac

#include <iostream>
#include <stdio.h>

using namespace std;

struct Point
{
    int x,y;
    Point(){}
    Point(int _x,int _y)
    {
        x=_x;
        y=_y;
    }
    Point operator -(const Point &b)const
    {
        return Point(x-b.x,y-b.y);
    }
    double operator ^(const Point &b)const
    {
        return x*b.y-y*b.x;
    }
    double operator *(const Point &b)const
    {
        return x*b.x+y*b.y;
    }
};

struct Line
{
    Point s,e;
    Line(){}
    Line(Point _s,Point _e)
    {
        s=_s;
        e=_e;
    }
};
Line line[200];
Point p[200];

bool OnSeg(Line l1,Line l2)
{
    return
    ((l1.s-l2.s)^(l1.e-l2.s))*((l1.s-l2.e)^(l1.e-l2.e))<0&&
    ((l2.e-l1.s)^(l2.s-l1.s))*((l2.e-l1.e)^(l2.s-l1.e))<0;
}
int main()
{
    int n,m;
    while(1)
    {
        scanf("%d %d",&n,&m);
        if(n==0&&m==0)
            break;
        int m;
        scanf("%d",&m);
        int cont=0;
        for(int i=0;i<=m;i++)
        {
            scanf("%d %d",&p[i].x,&p[i].y);
            if(i>=1)
            {
                line[cont]=Line(p[i],p[i-1]);
                cont++;
            }
        }
        int sum=0;
        for(int i=0;i<cont;i++)
        {
            for(int j=0;j<cont;j++)
            {
                if(j!=i)
                    if(OnSeg(line[i],line[j]))
                        sum++;
            }
        }
        cout<<(m+1+sum/2)<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/leekerian/article/details/81104498
今日推荐