• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            應用平面圖的歐拉定理:V + F - E = 2
            兩兩線段求交,得到交點數 V,然后判斷每個交點落在幾條邊上,如果一個點在一條邊上,這條邊就分裂成兩條邊,邊數加 1。這樣得到邊數 E。最后直接用歐拉定理解得 F。


            /*************************************************************************
            Author: WHU_GCC
            Created Time: 2007-8-20 12:52:55
            File Name: pku2284.cpp
            Description: 
            ***********************************************************************
            */

            #include 
            <iostream>
            #include 
            <cmath>
            using namespace std;
            #define out(x) (cout<<#x<<": "<<x<<endl)
            const int maxint=0x7FFFFFFF;
            typedef 
            long long int64;
            const int64 maxint64 = 0x7FFFFFFFFFFFFFFFLL;
            template
            <class T>void show(T a, int n){for(int i=0; i<n; ++i) cout<<a[i]<<' '; cout<<endl;}
            template
            <class T>void show(T a, int r, int l){for(int i=0; i<r; ++i)show(a[i],l);cout<<endl;}

            const double INF = 1e200;
            const double EP = 1e-10;

            struct point_t
            {
                
            double x, y;
                point_t(
            double a = 0double b = 0)
                
            {
                    x 
            = a;
                    y 
            = b;
                }

            }
            ;

            struct lineseg_t
            {
                point_t s, e;
                lineseg_t (point_t a, point_t b)
                
            {
                    s 
            = a;
                    e 
            = b;
                }

                lineseg_t()
                
            {}
            }
            ;

            struct line_t
            {
                
            double a, b, c;
            }
            ;

            bool operator <(point_t p1, point_t p2)
            {
                
            return p1.x < p2.x || p1.x == p2.x && p1.y < p2.y;
            }



            bool operator ==(point_t p1, point_t p2)
            {
                
            return abs(p1.x - p2.x) < EP && abs(p1.y - p2.y) < EP;
            }


            double multiply(point_t sp, point_t ep, point_t op)
            {
                
            return (sp.x - op.x) * (ep.y - op.y) - (ep.x - op.x) * (sp.y - op.y);
            }


            bool online(lineseg_t l, point_t p)
            {
                
            return abs(multiply(l.e, p, l.s)) < EP && (p.x - l.s.x) * (p.x - l.e.x) < EP && (p.y - l.s.y) * (p.y - l.e.y) < EP;
            }


            bool lineintersect(line_t l1, line_t l2, point_t &p)
            {
                
            double d = l1.a * l2.b - l2.a * l1.b;
                
            if (abs(d) < EP) return false;
                p.x 
            = (l2.c * l1.b - l1.c * l2.b) / d;
                p.y 
            = (l2.a * l1.c - l1.a * l2.c) / d;
                
            return true;
            }


            line_t makeline(point_t p1, point_t p2)
            {
                line_t t1;
                
            int sign = 1;
                t1.a 
            = p2.y - p1.y;
                
            if (t1.a < 0)
                
            {
                    sign 
            = -1;
                    t1.a 
            = sign * t1.a;
                }

                t1.b 
            = sign * (p1.x - p2.x);
                t1.c 
            = sign * (p1.y * p2.x - p1.x * p2.y);
                
            return t1;
            }


            bool intersection(lineseg_t l1, lineseg_t l2, point_t &p)
            {
                line_t ll1, ll2;
                ll1 
            = makeline(l1.s, l1.e);
                ll2 
            = makeline(l2.s, l2.e);
                
            if (lineintersect(ll1, ll2, p))
                    
            return online(l1, p) && online(l2, p);
                
            else return false;
            }


            const int maxn = 100000;
            point_t p[maxn];
            int n;

            point_t inter[maxn];
            int cnt_inter;

            int main()
            {
                
            int ca = 1;
                
            while (scanf("%d"&n), n != 0)
                
            {
                    
            for (int i = 0; i < n; i++)
                        scanf(
            "%lf%lf"&p[i].x, &p[i].y);
                    
                    cnt_inter 
            = 0;
                    
            for (int i = 0; i < n; i++)
                        
            for (int j = 0; j < n; j++)
                        
            {
                            lineseg_t l1(p[i], p[(i 
            + 1% n]), l2(p[j], p[(j + 1% n]);
                            point_t p;
                            
            if (intersection(l1, l2, p))
                                inter[cnt_inter
            ++= p;
                        }

                    sort(inter, inter 
            + cnt_inter);
                    cnt_inter 
            = unique(inter, inter + cnt_inter) - inter;
                    
                    
            int e = 0;
                    
            for (int i = 0; i < cnt_inter; i++)
                    
            {
                        
            for (int j = 0; j < n; j++)
                        
            {
                            lineseg_t t(p[j], p[(j 
            + 1% n]);
                            
            if (online(t, inter[i]) && !(t.s == inter[i]))
                                e
            ++;
                        }

                    }

                    printf(
            "Case %d: There are %d pieces.\n", ca++, e + 2 - cnt_inter);
                }

                
            return 0;
            }
            posted on 2007-08-21 17:26 Felicia 閱讀(356) 評論(0)  編輯 收藏 引用 所屬分類: 計算幾何
             
            久久国产精品视频| 99久久免费国产精品热| 久久综合香蕉国产蜜臀AV| 伊人丁香狠狠色综合久久| 久久久久久国产精品美女| 欧美久久一级内射wwwwww.| 久久久噜噜噜久久中文福利| 久久九色综合九色99伊人| 99精品国产在热久久| 久久无码人妻一区二区三区 | 精品久久久无码中文字幕天天| 久久笫一福利免费导航| 久久五月精品中文字幕| 国产女人aaa级久久久级| 中文字幕成人精品久久不卡| 久久99热国产这有精品| 2020最新久久久视精品爱| 精品久久一区二区三区| 久久精品成人免费国产片小草| 久久高潮一级毛片免费| 午夜精品久久影院蜜桃| 中文字幕久久亚洲一区| 国内精品久久久久影院薰衣草| 久久人妻AV中文字幕| 国产色综合久久无码有码| 久久亚洲私人国产精品| AAA级久久久精品无码区| 亚洲国产成人久久笫一页| 国产亚洲美女精品久久久2020| 大伊人青草狠狠久久| 久久99国产一区二区三区| 久久久WWW成人免费精品| 欧美粉嫩小泬久久久久久久 | 好属妞这里只有精品久久| 国产精品欧美久久久天天影视| 久久精品国产黑森林| 久久精品国产一区二区 | 国产免费久久精品99re丫y| 国产精品欧美亚洲韩国日本久久| 久久久精品一区二区三区| 久久精品国产半推半就|