• <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ⅴ| 欧美久久综合九色综合| 中文精品久久久久人妻| 亚洲伊人久久精品影院| 国产精品久久久久AV福利动漫| 欧美精品一区二区精品久久| 色综合久久久久综合99| 久久AV无码精品人妻糸列| 精品久久久久中文字幕一区| 2021最新久久久视精品爱| 99久久精品免费| 久久精品国产亚洲一区二区| 色婷婷综合久久久中文字幕 | 久久久久久久精品妇女99| 麻豆亚洲AV永久无码精品久久| 亚洲国产精品久久久久婷婷老年 | 久久99国产精品久久99小说| 韩国免费A级毛片久久| 人妻少妇精品久久| 99久久婷婷国产一区二区| 亚洲av日韩精品久久久久久a| 综合久久精品色| 国产福利电影一区二区三区,免费久久久久久久精 | 日韩欧美亚洲综合久久影院d3| 精品国产日韩久久亚洲| 久久精品女人天堂AV麻| 久久精品亚洲精品国产欧美| 国内精品久久久久影院日本| 国产激情久久久久久熟女老人| 99久久精品免费观看国产| 成人综合伊人五月婷久久| 精品久久人人爽天天玩人人妻| 欧美国产成人久久精品| 国内高清久久久久久| 噜噜噜色噜噜噜久久| 久久精品一本到99热免费| 亚洲欧美日韩久久精品| 亚洲乱码日产精品a级毛片久久| 久久久久国产| 亚洲精品视频久久久| 色老头网站久久网|