• <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 糯米 閱讀(270) 評論(0)  編輯 收藏 引用

            精品国产乱码久久久久久1区2区 | 久久青青草原国产精品免费| 色欲av伊人久久大香线蕉影院| 性高湖久久久久久久久| 亚洲精品无码久久千人斩| 伊人久久综在合线亚洲2019 | 久久精品国产亚洲精品| 久久久久久久波多野结衣高潮| 91视频国产91久久久| 亚洲精品国产第一综合99久久| 99久久超碰中文字幕伊人| 日产久久强奸免费的看| 欧美综合天天夜夜久久| 97久久国产综合精品女不卡 | 久久中文精品无码中文字幕| 久久99热只有频精品8| 一本色道久久综合狠狠躁篇| 国产韩国精品一区二区三区久久| 久久亚洲精品国产精品婷婷| 久久综合九色综合久99| 欧美噜噜久久久XXX| 国产精品亚洲综合久久| 色综合合久久天天给综看| 91久久国产视频| 亚洲国产二区三区久久| 国产精品99久久99久久久| 亚洲精品无码久久久久| 一本色道久久88精品综合| 日韩电影久久久被窝网| 国产精品成人99久久久久| 久久最近最新中文字幕大全 | 久久婷婷是五月综合色狠狠| 久久精品亚洲一区二区三区浴池 | 久久亚洲电影| 国产精品99久久久久久宅男 | 国产精品嫩草影院久久| 日本免费一区二区久久人人澡 | 亚洲综合久久综合激情久久| 久久综合丁香激情久久| 99久久99久久精品国产片果冻| 999久久久无码国产精品|