That Nice Euler Circuit_欧拉定理求平面区域数

欧拉定理:V为平面图定点数,E为平面边数,F为平面区域数,则V+F-E=2;
题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,图案是一条闭合曲线,组成一笔画的线段可以相交,但是不会不分重叠,求这些线段将平面分为多少部分。
题解:平面的节点由原来的节点和相交得到的新节点组成,有可能出现重复计数的交点,即三线共点,需要去重。

#include
#include
#include
#include
#define maxn 305
using namespace std;
struct Point
{
    double x,y;
    Point(double x=0,double y=0):x(x),y(y){}

};
typedef Point Vector;
Vector operator +(Vector A,Vector B) {return Vector(A.x+B.x,A.y+B.y);}
Vector operator -(Vector A,Vector B) {return Vector(A.x-B.x,A.y-B.y);}
Vector operator *(Vector A,double p) {return Vector(A.x*p,A.y*p);}
Vector operator /(Vector A,double p) {return Vector(A.x/p,A.y/p);}
bool operator <(const Point &a,const Point &b)
{
    return a.x0) return length(v3);
    else return fabs(cross(v1,v2))/length(v1);
}
Point getLineProjection(Point P,Point A,Point B)//p点在AB直线上的投影
{
    Vector v=B-A;
    return A+v*(dot(v,P-A)/dot(v,v));
}
bool segmentProperIntersection(Point a1,Point a2,Point b1,Point b2)
{   //两直线是否规范相交:恰好有一个公共点并且公共点不在任何一条线段的端点
    double c1=cross(a2-a1,b1-a1),c2=cross(a2-a1,b2-a1),
           c3=cross(b2-b1,a1-b1),c4=cross(b2-b1,a2-b1);
           return dcmp(c1)*dcmp(c2)<0&&dcmp(c3)*dcmp(c4)<0;
}
bool onSegment(Point p,Point a1,Point a2)//p点是否在线段上,不包括a1,a2
{
    return dcmp(cross(a1-p,a2-p))==0&&dcmp(dot(a1-p,a2-p))<0;
}
double convexPolygonArea(Point *arr,int n)//计算多边形面积
{
    double area=0.0;
    for(int i=1;i

你可能感兴趣的:(That Nice Euler Circuit_欧拉定理求平面区域数)