• <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>

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

             

            /*************************************************************************
            Author: WHU_GCC
            Created Time: 2007-8-21 15:56:29
            File Name: pku1151.cpp
            Description: 
            ***********************************************************************
            */

            #include 
            <iostream>
            #include 
            <cmath>
            using namespace std;

            #define out(x) (cout << #x << ": " << x << endl)
            typedef 
            long long int64;
            const int maxint = 0x7FFFFFFF;
            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 = 1000;

            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()
            {
                
            int ca = 1;
                
            while (scanf("%d"&n), n != 0)
                
            {
                    cnt_x 
            = 0;
                    cnt_line 
            = 0;
                    
            for (int i = 0; i < n; i++)
                    
            {
                        
            double x1, y1, x2, y2;
                        scanf(
            "%lf%lf%lf%lf"&x1, &y1, &x2, &y2);
                        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;

                    
            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(
            "Test case #%d\n", ca++);
                    printf(
            "Total explored area: %.2lf\n\n", area);
                }

                
            return 0;
            }
            posted on 2007-08-21 16:39 Felicia 閱讀(595) 評論(1)  編輯 收藏 引用 所屬分類: 計算幾何
            Comments
             
            国产高清国内精品福利99久久| 欧美麻豆久久久久久中文| 国产91色综合久久免费| 中文字幕亚洲综合久久| 亚洲国产一成久久精品国产成人综合 | 少妇内射兰兰久久| 久久99精品国产| 色播久久人人爽人人爽人人片AV| 国产精品一区二区久久不卡| 日韩va亚洲va欧美va久久| 精品久久久久久国产| 久久香综合精品久久伊人| 大蕉久久伊人中文字幕| 久久久久亚洲av无码专区喷水| 久久久久国产精品嫩草影院| 成人久久久观看免费毛片| 中文字幕久久精品无码| 久久国产综合精品五月天| 精品久久久久中文字幕日本| 久久香综合精品久久伊人| 欧美久久久久久精选9999| 99久久www免费人成精品| 久久国产精品成人片免费| 久久婷婷国产剧情内射白浆| 久久久精品人妻无码专区不卡 | AV无码久久久久不卡蜜桃| 热99re久久国超精品首页| 日本强好片久久久久久AAA | 久久99国产精品99久久| 国色天香久久久久久久小说 | 久久久久亚洲精品天堂| 思思久久好好热精品国产| 日韩电影久久久被窝网| 亚洲精品成人久久久| 少妇久久久久久被弄到高潮| 欧美麻豆久久久久久中文| 久久精品成人免费观看97| 久久久精品人妻无码专区不卡| 久久强奷乱码老熟女网站| 亚州日韩精品专区久久久| 久久婷婷色综合一区二区|