• <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
            數(shù)據(jù)加載中……

            POJ 2843 Cutting Cake 并查集

            思路:

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

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

            代碼是照著解題報告寫的,不過還是很爛,好像3000+ms,實在佩服那些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 糯米 閱讀(328) 評論(1)  編輯 收藏 引用 所屬分類: POJ

            評論

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

            請問你上面e:\test\in.txt里面是什么內(nèi)容,我也在想這個問題,但是沒弄明白,想用你代碼運行一下,謝謝了 我郵箱:236602203@qq.com
            2010-04-10 00:46 | 卡卡
            久久久精品国产Sm最大网站| 国产精品久久网| 三级三级久久三级久久 | 久久ww精品w免费人成| 91精品国产91久久久久久青草| 久久男人中文字幕资源站| 亚洲国产精品成人久久| 99久久国产亚洲高清观看2024 | 伊人久久大香线蕉av不变影院| 精品无码久久久久久尤物| 久久精品国产精品亚洲人人 | 久久99精品久久只有精品| 久久精品国产亚洲av瑜伽| 久久久噜噜噜www成人网| 无码乱码观看精品久久| 精品999久久久久久中文字幕| 亚洲伊人久久成综合人影院| 成人国内精品久久久久影院VR| 亚洲va久久久噜噜噜久久男同 | 777米奇久久最新地址| 久久人人爽人人爽人人片AV东京热 | 久久亚洲AV成人无码| 久久精品三级视频| 国产三级精品久久| 久久九九有精品国产23百花影院| 日韩精品久久无码人妻中文字幕 | 国产免费久久久久久无码| 亚洲狠狠综合久久| 91精品国产综合久久精品| 香蕉久久av一区二区三区| av色综合久久天堂av色综合在| 热RE99久久精品国产66热| 久久久久久极精品久久久| 久久精品成人免费观看97| 精品久久久久久无码国产| 亚洲国产天堂久久综合网站| 国产福利电影一区二区三区久久久久成人精品综合 | 奇米影视7777久久精品| 亚洲欧美伊人久久综合一区二区| 精品人妻伦九区久久AAA片69| 尹人香蕉久久99天天拍|