• <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)  編輯 收藏 引用

            亚洲综合日韩久久成人AV| 99国产精品久久久久久久成人热| 亚洲一区二区三区日本久久九| 久久国产精品一区二区| 国产精品99久久不卡| 思思久久精品在热线热| 国产综合久久久久| 青青草国产97免久久费观看| 一本久久知道综合久久| 国产精品免费久久久久久久久| 久久午夜无码鲁丝片午夜精品| 97久久国产综合精品女不卡| 亚洲国产成人久久综合一| 思思久久99热只有频精品66| 国产91久久精品一区二区| 久久这里都是精品| 国产成人精品久久亚洲高清不卡 | 亚洲欧洲日产国码无码久久99| 精品综合久久久久久98| 韩国三级中文字幕hd久久精品| 久久国产乱子伦免费精品| 午夜精品久久影院蜜桃| 情人伊人久久综合亚洲| 精品无码久久久久国产| 久久久久青草线蕉综合超碰| 精品久久人人做人人爽综合| 精品精品国产自在久久高清| 久久亚洲精精品中文字幕| 亚洲?V乱码久久精品蜜桃| 国产亚州精品女人久久久久久 | 国产精品日韩深夜福利久久| MM131亚洲国产美女久久| 久久精品国产久精国产一老狼| 久久夜色精品国产www| 久久91精品国产91久久麻豆| 久久精品人人做人人爽电影蜜月 | 无码人妻久久久一区二区三区| 四虎影视久久久免费| 久久久免费观成人影院| 久久精品亚洲精品国产欧美| 精品久久久久久久久久久久久久久 |