• <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 2843 Cutting Cake 并查集

            思路:

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

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

            代碼是照著解題報告寫的,不過還是很爛,好像3000+ms,實在佩服那些1000ms內的神牛們!

            #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 糯米 閱讀(319) 評論(1)  編輯 收藏 引用 所屬分類: POJ

            評論

            # re: POJ 2843 Cutting Cake 并查集  回復  更多評論   

            請問你上面e:\test\in.txt里面是什么內容,我也在想這個問題,但是沒弄明白,想用你代碼運行一下,謝謝了 我郵箱:236602203@qq.com
            2010-04-10 00:46 | 卡卡
            人人狠狠综合久久亚洲高清| 精品国产综合区久久久久久| 漂亮人妻被黑人久久精品| 久久综合噜噜激激的五月天| 国产一区二区三区久久| 亚洲精品美女久久久久99小说 | 狠狠88综合久久久久综合网| 91视频国产91久久久| 亚洲精品视频久久久| 久久中文字幕一区二区| 久久毛片一区二区| 国产精品青草久久久久福利99| 亚洲国产精品成人久久| 国産精品久久久久久久| 久久精品中文无码资源站 | 久久精品国产99久久无毒不卡 | 人妻少妇精品久久| 国产精品狼人久久久久影院| 国内精品久久久久影院日本| 久久国产劲爆AV内射—百度| 久久夜色撩人精品国产小说| 亚洲乱亚洲乱淫久久| 久久精品国产99国产精品澳门| 无码国内精品久久人妻| 99精品国产免费久久久久久下载 | 久久精品国产亚洲av麻豆蜜芽| 久久99亚洲综合精品首页| 99久久人人爽亚洲精品美女| 国产精品久久国产精品99盘 | 久久综合五月丁香久久激情| 久久久中文字幕| 亚洲伊人久久大香线蕉苏妲己| 久久久精品人妻一区二区三区蜜桃| 久久精品aⅴ无码中文字字幕不卡| 亚洲精品NV久久久久久久久久 | 狠色狠色狠狠色综合久久| 久久婷婷五月综合国产尤物app| 久久婷婷五月综合色奶水99啪| 亚洲精品国精品久久99热| 日本WV一本一道久久香蕉| 模特私拍国产精品久久|