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

            糯米

            TI DaVinci, gstreamer, ffmpeg
            隨筆 - 167, 文章 - 0, 評論 - 47, 引用 - 0
            數據加載中……

            POJ 3168 Barn Expansion 快排

            思路:

            一開始想到用線段樹來做,但是發現坐標范圍異常的大,放一個都勉勉強強,更不用說幾個了!
            想了一下,發現有一個至關重要的條件“不存在覆蓋的情況”。
            那就沒必要用線段樹了,因為壓根就沒必要解決覆蓋問題。
            可以用一種取巧的方法解決這題。



            對于每個矩形,首先把它 y 方向的兩條邊抽取出來。
            對于所有矩形的 y 方向的邊,先按照 x 排序,然后按照頂端的 y 坐標排序。



            然后對于位于同一 x 坐標的邊,找出所有首尾相接或者有交集的邊。
            那么這些邊對應的矩形必定要排除。

            對于 x 方向的邊,作同樣的處理。

            排除完之后,剩下的矩形就是可以答案了。

            代碼 500 多ms。。
            #include <stdio.h>
            #include 
            <stdlib.h>

            #define MAX_N 25032

            struct node {
                
            int barn, start, end, idx;
            }
            ;
            struct node vert[MAX_N * 2], hori[MAX_N * 2];
            char cannot[MAX_N];
            int N, ans;

            __inline 
            void add_node(struct node *t, int barn, int start, int end, int idx)
            {
                t
            ->barn = barn;
                t
            ->start = start;
                t
            ->end = end;
                t
            ->idx = idx;
            }


            int cmp_node(const void *a, const void *b)
            {
                
            struct node *p, *q;
                p 
            = (struct node *)a;
                q 
            = (struct node *)b;
                
            if (p->idx != q->idx)
                    
            return p->idx - q->idx;
                
            return p->start - q->start;
            }


            __inline 
            void disable_barn(int barn)
            {
                
            if (!cannot[barn]) {
                    cannot[barn] 
            = 1;
                    ans
            --;
                }
             
            }


            __inline 
            void calc(struct node *arr, int len)
            {
                
            int i, idx, end, cnt, first;

                i 
            = 0;
                
            while (i < len) {
                    idx 
            = arr[i].idx;
                    end 
            = arr[i].end;
                    first 
            = i;
                    cnt 
            = 0;
                    i
            ++;
                    
            while (i < len && arr[i].idx == idx && arr[i].start <= end) {
                        
            if (arr[i].end > end)
                            end 
            = arr[i].end;
                        disable_barn(arr[i].barn);
                        cnt
            ++;
                        i
            ++;
                    }

                    
            if (cnt)
                        disable_barn(arr[first].barn);
                }

            }


            int main()
            {
                
            int i, top, left, bottom, right;

                freopen(
            "e:\\test\\in.txt""r", stdin);

                scanf(
            "%d"&N);
                ans 
            = N;
                
            for (i = 0; i < N; i++{
                    scanf(
            "%d%d%d%d"&left, &bottom, &right, &top);
                    add_node(
            &vert[i * 2], i, bottom, top, left);
                    add_node(
            &vert[i * 2 + 1], i, bottom, top, right);
                    add_node(
            &hori[i * 2], i, left, right, top);
                    add_node(
            &hori[i * 2 + 1], i, left, right, bottom);
                }

                qsort(vert, N 
            * 2sizeof(vert[0]), cmp_node);
                qsort(hori, N 
            * 2sizeof(hori[0]), cmp_node);
                calc(vert, N 
            * 2);
                calc(hori, N 
            * 2);
                printf(
            "%d\n", ans);

                
            return 0;
            }


            posted on 2010-03-18 15:52 糯米 閱讀(642) 評論(0)  編輯 收藏 引用 所屬分類: POJ

            国产一区二区精品久久凹凸 | 亚洲精品乱码久久久久久蜜桃 | 久久综合久久综合九色| 性高湖久久久久久久久| 久久青青草原精品国产不卡| 日韩乱码人妻无码中文字幕久久| 99久久精品费精品国产| 久久久无码人妻精品无码| 久久九色综合九色99伊人| 国产精品99久久久久久董美香| 亚洲国产成人久久笫一页| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 久久综合给合久久狠狠狠97色| 欧美精品丝袜久久久中文字幕| 国产AV影片久久久久久| 久久久久婷婷| 中文字幕日本人妻久久久免费 | 久久久无码人妻精品无码| 亚洲中文久久精品无码| 亚洲中文字幕无码久久综合网 | 久久九九久精品国产| 亚洲精品无码久久久影院相关影片 | 亚洲国产精品成人久久蜜臀 | 久久久久亚洲AV成人网人人网站| 亚洲国产另类久久久精品| 狠狠久久亚洲欧美专区| 无码精品久久一区二区三区| 99久久超碰中文字幕伊人| 久久久久亚洲av无码专区导航| 狠狠色丁香久久婷婷综合| 伊人久久精品无码二区麻豆| 狠狠色噜噜色狠狠狠综合久久| 久久久久久亚洲精品影院| 久久无码AV中文出轨人妻| 久久国产精品国产自线拍免费 | 99久久综合狠狠综合久久| 久久一区二区免费播放| 亚洲国产精品一区二区久久hs | 精品一二三区久久aaa片| 国产高潮国产高潮久久久91 | 狠狠久久亚洲欧美专区|