• <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, 評(píng)論 - 47, 引用 - 0
            數(shù)據(jù)加載中……

            POJ 2843 Cutting Cake 并查集

            思路:

            這題目非常牛逼!是道月賽的題目!看完題目我就放棄了。。直接看解題報(bào)告。
            解法果然牛逼!

            解題報(bào)告鏈接在此:
            http://acm.pku.edu.cn/JudgeOnline/images/contestreport/200606/G.htm

            代碼是照著解題報(bào)告寫的,不過還是很爛,好像3000+ms,實(shí)在佩服那些1000ms內(nèi)的神牛們!

            #include <stdio.h>

            #define MAX_N 1024

            struct queue_node {
                
            int y, x;
            }
            ;

            int set[MAX_N][MAX_N], cut[MAX_N][MAX_N];
            int N, M;
            int left, top, right, bottom;

            struct queue_node queue[MAX_N * MAX_N];
            int head, tail;

            inline 
            int find(int *arr, int idx)
            {
                
            static int stk[MAX_N * MAX_N], sp;

                
            for (sp = 0; arr[idx]; idx = arr[idx])
                    stk[sp
            ++= idx;
                
            for (sp--; sp >= 0; sp--)
                    arr[stk[sp]] 
            = idx;

                
            return idx;
            }


            inline 
            void push(int y, int x)
            {
                
            if (x < left || x > right || y < top || y > bottom)
                    
            return ;
                
            if (cut[y][x])
                    
            return ;
                
                cut[y][x] 
            = 1;
                
            if (cut[y][x - 1&& cut[y][x + 1]) {
                    
            set[y][x] = x + 1;
                    
            set[y][x - 1= x + 1;
                }
             else if (cut[y][x - 1]) 
                    
            set[y][x - 1= x;
                
            else if (cut[y][x + 1])
                    
            set[y][x] = x + 1;
                
                queue[tail].y 
            = y;
                queue[tail].x 
            = x;
                tail
            ++;
            }


            inline 
            int bfs(int y, int x)
            {
                x 
            = find(set[y], x);
                
            if (cut[y][x])
                    x
            ++;
                
            if (x > right)
                    
            return 0;

                head 
            = tail = 0;
                push(y, x);
                
            while (head != tail) {
                    y 
            = queue[head].y;
                    x 
            = queue[head].x;
                    head
            ++;
                    push(y 
            - 1, x);
                    push(y 
            + 1, x);
                    push(y, x 
            - 1);
                    push(y, x 
            + 1);
                }


                
            return 1;
            }


            int main()
            {
                
            int i, j, ans;

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

                scanf(
            "%d%d"&N, &M);
                
            while (M--{
                    scanf(
            "%d%d%d%d"&left, &top, &right, &bottom);
                    ans 
            = 0;
                    
            for (i = top; i <= bottom; i++)
                        
            while (bfs(i, left))
                            ans
            ++;
                    printf(
            "%d\n", ans);
                }


                
            return 0;
            }

            posted on 2010-04-06 22:40 糯米 閱讀(314) 評(píng)論(1)  編輯 收藏 引用 所屬分類: POJ

            評(píng)論

            # re: POJ 2843 Cutting Cake 并查集  回復(fù)  更多評(píng)論   

            請(qǐng)問你上面e:\test\in.txt里面是什么內(nèi)容,我也在想這個(gè)問題,但是沒弄明白,想用你代碼運(yùn)行一下,謝謝了 我郵箱:236602203@qq.com
            2010-04-10 00:46 | 卡卡
            亚洲&#228;v永久无码精品天堂久久| 国产一区二区精品久久岳| 久久免费国产精品| 综合久久精品色| 99久久免费国产特黄| 精品国产91久久久久久久a| 久久久久婷婷| 久久亚洲精品中文字幕| 国产真实乱对白精彩久久| 中文字幕久久精品| 99久久人妻无码精品系列蜜桃| 中文字幕久久精品| 欧美一区二区精品久久| 狠狠色婷婷久久综合频道日韩 | 久久国产成人亚洲精品影院| 一级女性全黄久久生活片免费| 久久大香香蕉国产| 久久综合亚洲欧美成人| 精品久久久久中文字| 久久婷婷成人综合色综合| 婷婷国产天堂久久综合五月| 久久本道伊人久久| 色偷偷偷久久伊人大杳蕉| 欧美久久亚洲精品| 7国产欧美日韩综合天堂中文久久久久 | 久久久久久国产a免费观看黄色大片 | 日本欧美久久久久免费播放网| 亚洲精品高清国产一久久| 一本一本久久aa综合精品| 国产精品成人久久久久久久| 亚洲狠狠综合久久| 69久久夜色精品国产69| 无码人妻少妇久久中文字幕蜜桃 | 亚洲国产成人久久综合区| 91久久成人免费| 99国产欧美精品久久久蜜芽| 97精品依人久久久大香线蕉97| 亚洲午夜无码AV毛片久久| 久久综合精品国产一区二区三区| 99久久精品这里只有精品| 久久精品国产福利国产秒|