• <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>
            跟pku1151是一樣的。
            題目給出 n 個矩形,要求它們的面積并。具體做法是離散化。先把 2n 個 x 坐標排序去重,然后再把所有水平線段(要記錄是矩形上邊還是下邊)按 y 坐標排序。最后對于每一小段區間 (x[i], x[i + 1]) 掃描所有的水平線段,求出這些水平線段在小區間內覆蓋的面積。總的時間復雜度是 O(n2)。利用線段樹,可以優化到 O(nlogn)。

            /*************************************************************************
            Author: WHU_GCC
            Created Time: 2007-8-25 17:41:41
            File Name: pku1389.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 int maxn = 4010;

            typedef 
            struct line_t
            {
                
            double l, r, y;
                
            int flag;
            }
            ;

            bool operator <(const line_t &a, const line_t &b)
            {
                
            return a.y < b.y;
            }


            bool d_equal(const double &a, const double &b)
            {
                
            return abs(a - b) < 1e-9;
            }


            int n;
            double x[maxn];
            int cnt_x, cnt_line;
            line_t line[maxn];

            int main()
            {
                
            while (1)
                
            {
                    cnt_x 
            = 0;
                    cnt_line 
            = 0;
                    
            while (1)
                    
            {
                        
            double x1, y1, x2, y2;
                        scanf(
            "%lf%lf%lf%lf"&x1, &y1, &x2, &y2);
                        
            if (x1 == -1.0break;
                        x[cnt_x
            ++= x1;
                        x[cnt_x
            ++= x2;
                        line[cnt_line].flag 
            = 0;
                        line[cnt_line].l 
            = x1;
                        line[cnt_line].r 
            = x2;
                        line[cnt_line
            ++].y = y1;
                        line[cnt_line].flag 
            = 1;
                        line[cnt_line].l 
            = x1;
                        line[cnt_line].r 
            = x2;
                        line[cnt_line
            ++].y = y2;
                    }

                    sort(line, line 
            + cnt_line);
                    sort(x, x 
            + cnt_x);
                    cnt_x 
            = unique(x, x + cnt_x, d_equal) - x;
                    
            if (cnt_x == 0break;
                    
            double area = 0.0;
                    
            for (int i = 0; i < cnt_x - 1; i++)
                    
            {
                        
            int cnt = 0;
                        
            double now_y;
                        
            for (int j = 0; j < cnt_line; j++if (line[j].l <= x[i] && line[j].r >= x[i + 1])
                        
            {
                            
            if (cnt == 0) now_y = line[j].y;
                            
            if (line[j].flag == 0) cnt++;
                            
            else cnt--;
                            
            if (cnt == 0) area += (x[i + 1- x[i]) * (line[j].y - now_y);
                        }

                    }

                    printf(
            "%.0lf\n", area);
                }

                
            return 0;
            }
            posted on 2007-08-25 17:53 Felicia 閱讀(446) 評論(0)  編輯 收藏 引用 所屬分類: 計算幾何
             
            亚洲狠狠婷婷综合久久蜜芽| 久久99国产精品尤物| 香蕉久久夜色精品国产2020| 香蕉99久久国产综合精品宅男自 | 亚洲一本综合久久| 欧美成a人片免费看久久| 国产精品美女久久福利网站| 久久精品国产99久久久| 91麻精品国产91久久久久| 亚洲精品NV久久久久久久久久| 久久人人添人人爽添人人片牛牛 | 久久久亚洲裙底偷窥综合| 久久国产精品国产自线拍免费| 久久久精品久久久久影院| 久久精品免费观看| 国产综合久久久久| 亚洲AV日韩AV永久无码久久| 久久精品国产色蜜蜜麻豆| 丰满少妇人妻久久久久久| 久久久亚洲欧洲日产国码是AV| 久久久久久无码国产精品中文字幕 | 无码国产69精品久久久久网站 | MM131亚洲国产美女久久| av色综合久久天堂av色综合在| 久久免费视频6| 久久久久成人精品无码 | 亚洲а∨天堂久久精品9966| 大香网伊人久久综合网2020| 久久久久中文字幕| 狠狠干狠狠久久| 99久久成人18免费网站| 久久99精品综合国产首页| 东京热TOKYO综合久久精品| 久久精品国产亚洲AV高清热| 色综合久久无码中文字幕| 久久精品国产男包| 久久综合久久自在自线精品自| 亚洲狠狠婷婷综合久久蜜芽| 久久国产精品99国产精| 国产欧美一区二区久久| 国内精品免费久久影院|