zoukankan      html  css  js  c++  java
  • pku 2284 That Nice Euler Circuit

    题意:

    给你n个点第n个点保证与第0个点相交,然后求这n个点组成的图形可以把整个平面分成几个面

    思路:

    这里的解题关键是知道关于多面体的欧拉定理 

    多面体:

    设v为顶点数,e为棱数,f是面数,则
    v-e+f=2-2p
    p为欧拉示性数,例如
    p=0 的多面体叫第零类多面体
    p=1 的多面体叫第一类多面体

    这里满足的是零类多面体,我们只要求出该图形的 点v,边e即可。 怎么求点v呢? 两部分一部分是原来的n-1个顶点,然后是交出来的,我们只要判断线段相交求直线交点即可,然偶可能会摇头重复的交点去掉,求边的话我们只要求出一个规范相交的点肯定会增加一条边,枚举点然后判断 点是否在线段上(除了端点),然偶求解即可。

    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <vector>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <set>
    #include <functional>
    #include <numeric>
    #include <sstream>
    #include <stack>
    #include <map>
    #include <queue>
    
    #define CL(arr, val) memset(arr, val, sizeof(arr))
    
    #define lc l,m,rt<<1
    #define rc m + 1,r,rt<<1|1
    #define pi acos(-1.0)
    #define L(x)    (x) << 1
    #define R(x)    (x) << 1 | 1
    #define MID(l, r)   (l + r) >> 1
    #define Min(x, y)   (x) < (y) ? (x) : (y)
    #define Max(x, y)   (x) < (y) ? (y) : (x)
    #define E(x)        (1 << (x))
    #define iabs(x)     (x) < 0 ? -(x) : (x)
    #define OUT(x)  printf("%I64d
    ", x)
    #define lowbit(x)   (x)&(-x)
    #define Read()  freopen("din.txt", "r", stdin)
    #define Write() freopen("d.out", "w", stdout)
    #define ll unsigned long long
    #define keyTree (chd[chd[root][1]][0])
    
    #define M 100007
    #define N 317
    
    using namespace std;
    
    const int inf = 0x7f7f7f7f;
    const int mod = 1000000007;
    
    struct Point
    {
        double x,y;
        Point(double tx = 0,double ty = 0) : x(tx),y(ty){}
    };
    typedef Point Vtor;
    
    Vtor operator + (Vtor A,Vtor B) { return Vtor(A.x + B.x,A.y + B.y); }
    Vtor operator - (Point A,Point B) { return Vtor(A.x - B.x,A.y - B.y); }
    Vtor operator * (Vtor A,double p) { return Vtor(A.x*p,A.y*p); }
    Vtor operator / (Vtor A,double p) { return Vtor(A.x/p,A.y/p); }
    const double eps = 1e-8;
    int dcmp(double x) { if (fabs(x) < eps) return 0; else return x > 0? 1 : -1; }
    bool operator < (Point A,Point B) { return A.x < B.x || (A.x == B.x && A.y < B.y); }
    bool operator == (Point A,Point B) { return dcmp(A.x - B.x) == 0 && dcmp(A.y - B.y) == 0 ; }
    
    double Dot(Vtor A,Vtor B) { return A.x*B.x + A.y*B.y; }
    double Length(Vtor A) { return sqrt(Dot(A,A)); }
    double Angle(Vtor A,Vtor B) { return acos(Dot(A,B)/Length(A)/Length(B)); }
    double Cross(Vtor A,Vtor B) { return A.x*B.y - A.y*B.x; }
    double Area2(Point A,Point B,Point C) { return Cross(B - A,C - A); }
    Vtor Rotate(Vtor A,double rad) { return Vtor(A.x*cos(rad) - A.y*sin(rad),A.x*sin(rad) + A.y*cos(rad)); }
    /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
    
    bool SegmentPI(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*c2) < 0 && dcmp(c3*c4) < 0;
    
    }
    bool OnSegment(Point p,Point a1,Point a2)
    {
        return dcmp(Cross(a2 - p, a1 - p)) == 0 && dcmp(Dot(a2 - p,a1 - p)) < 0;
    }
    Point GetLineIn(Point P,Vtor v,Point Q,Vtor w)
    {
        Vtor u = P - Q;
        double t = Cross(w,u)/Cross(v,w);
        return P + v*t;
    }
    Point P[N],v[N*N];
    int n;
    
    int main()
    {
    
        Read();
        int Ei,Vi;
        int cas = 1;
        while (~scanf("%d",&n))
        {
            if (!n) break;
            Vi = 0;
            for (int i = 0; i < n; ++i)
            scanf("%lf%lf",&P[i].x,&P[i].y),v[Vi++] = P[i];
    
            Ei = --n;
            for (int i = 0; i < n; ++i)
            {
                for (int j = i + 1; j < n; ++j)
                {
                    if (SegmentPI(P[i],P[i + 1],P[j],P[j + 1]))
                    {
                        v[Vi++] = GetLineIn(P[i],P[i + 1] - P[i],P[j],P[j + 1] - P[j]);
                    }
                }
            }
            sort(v, v + Vi);
            Vi = unique(v,v + Vi) - v;
            for (int i = 0; i < Vi; ++i)
            {
                for (int j = 0; j < n; ++j)
                {
                    if (OnSegment(v[i],P[j],P[j + 1])) Ei++;
                }
            }
    //        printf("%d %d
    ",Vi,Ei);
            printf("Case %d: There are %d pieces.
    ",cas++,Ei - Vi + 2);
        }
    
        return 0;
    }
    View Code
  • 相关阅读:
    singleton 创建static类型的对象
    记忆曲线 遗忘曲线
    创建classic 得到函数 调用函数
    abstract factory 创建相互关联的类
    log4j PatternLayout
    C#中override重写与new隐藏的区别,以及C#与Java的override区别 转
    iptables如何做内网的https端口映射 转
    得到一棵树 取自表内自递归(即ID 与ParentID)
    Common.TcpLibTcpClientT
    得到汉字的首拼音字符 ZT
  • 原文地址:https://www.cnblogs.com/E-star/p/3188214.html
Copyright © 2011-2022 走看看