• <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
            數據加載中……

            HDU 2822 Dogs 寬搜

            這題用普通的寬搜可以解決。
            關鍵問題在于由于是寬搜,隊列里面的元素的step字段必須是從前往后遞增的。
            在碰到一大堆聯通的'X'之后,必須另外進行一次遍歷,同時的把這些'X'插入到隊列中,保持step字段的遞增。
            這樣做復雜度并不改變。

            #include <stdio.h>

            #define NR 1024

            struct node {
                
            short x, y;
                
            int s;
            }
            ;
            char map[NR][NR];
            struct node Q[NR*NR];
            int W, H;
            int sx, sy, ex, ey;
            int h, t, h2;

            inline 
            int inrange(short x, short y)
            {
                
            return x >= 0 && x < W && y >= 0 && y < H;
            }


            inline 
            void push2(short x, short y, int s)
            {
                
            if (!inrange(x, y))
                   
            return ;
                
            if (map[y][x] == 'X' || map[y][x] == '.'{
            //        printf("p2 %d %d %d\n", x, y, s);
                    Q[t].x = x;
                    Q[t].y 
            = y;
                    
            if (map[y][x] == '.'{
                        map[y][x] 
            = '#';
                        Q[t].s 
            = s + 1;
                    }
             else {
                        map[y][x] 
            = '$';
                        Q[t].s 
            = s;
                    }

                    t
            ++;
                }

            }


            inline 
            void bfs2(short x, short y, int s)
            {
                
            struct node n;

                push2(x, y, s);
                h2 
            = t - 1;
                
            while (h2 != t) {
                    n 
            = Q[h2++];
                    
            if (map[n.y][n.x] == '#')
                        
            continue;
                    push2(n.x 
            - 1, n.y, n.s);
                    push2(n.x 
            + 1, n.y, n.s);
                    push2(n.x, n.y 
            - 1, n.s);
                    push2(n.x, n.y 
            + 1, n.s);
                }

            }


            inline 
            void push(short x, short y, int s)
            {
                
            if (!inrange(x, y)) 
                    
            return ;
                
            if (map[y][x] == '.'{
            //        printf("p %d %d %d\n", x, y, s);
                    Q[t].x = x;
                    Q[t].y 
            = y;
                    Q[t].s 
            = s + 1;
                    t
            ++;
                    map[y][x] 
            = '@';
                }
             else if (map[y][x] == 'X')
                    bfs2(x, y, s);
            }


            inline 
            int bfs()
            {
                
            struct node n;

                t 
            = h = 0;
                push(sx, sy, 
            0);
                
            while (t != h) {
                    n 
            = Q[h++];
                    
            if (n.x == ex && n.y == ey)
                        
            return n.s;
                    
            if (map[n.y][n.x] == '$')
                        
            continue;
                    push(n.x 
            - 1, n.y, n.s);
                    push(n.x 
            + 1, n.y, n.s);
                    push(n.x, n.y 
            - 1, n.s);
                    push(n.x, n.y 
            + 1, n.s);
                }

            }


            int main()
            {
                
            int i;

                
            while (scanf("%d%d"&H, &W), H) {
                    
            for (i = 0; i < H; i++)
                        scanf(
            "%s", map[i]);
                    scanf(
            "%d%d%d%d"&sy, &sx, &ey, &ex);
                    sy
            --; sx--; ey--; ex--;
                    printf(
            "%d\n", bfs());
                }


                
            return 0;
            }

            posted on 2010-10-25 22:06 糯米 閱讀(266) 評論(0)  編輯 收藏 引用

            国产精品久久久久a影院| 久久―日本道色综合久久| 狠狠88综合久久久久综合网| 久久香蕉国产线看观看精品yw| 久久久久人妻一区精品色 | 日韩十八禁一区二区久久| 一日本道伊人久久综合影| 日韩精品久久久肉伦网站| 高清免费久久午夜精品| 久久久国产打桩机| 久久免费大片| 色综合久久精品中文字幕首页| 久久中文字幕视频、最近更新| 久久久久国产精品熟女影院| 久久久久九国产精品| 久久综合丁香激情久久| 久久久SS麻豆欧美国产日韩| 国产亚洲精久久久久久无码AV| AV狠狠色丁香婷婷综合久久 | 国产成人久久AV免费| 武侠古典久久婷婷狼人伊人| 久久精品视频免费| 曰曰摸天天摸人人看久久久| 久久精品国产91久久综合麻豆自制| 日韩中文久久| 久久97久久97精品免视看| 久久99精品国产一区二区三区| 久久久精品国产免大香伊| 亚洲精品成人久久久| 囯产精品久久久久久久久蜜桃| 久久99精品久久久大学生| 精品久久久久久无码国产| 久久夜色tv网站| 亚洲一区二区三区日本久久九| 狠狠色丁香婷综合久久| 久久久久久毛片免费播放| 久久婷婷五月综合国产尤物app | 久久国产精品成人片免费| 97久久国产综合精品女不卡| 国产精品久久久久久久app| 久久久久久综合网天天|