• <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, 評(píng)論 - 47, 引用 - 0
            數(shù)據(jù)加載中……

            HDU 2822 Dogs 寬搜

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

            #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) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            国产69精品久久久久9999APGF| 2019久久久高清456| 久久www免费人成看国产片| 久久久久亚洲AV成人网人人软件| 久久99国产精品久久99小说 | 国产成人精品久久| 久久99热这里只有精品国产| 久久91综合国产91久久精品| 亚洲日本久久久午夜精品| 人人狠狠综合久久亚洲88| 久久久亚洲裙底偷窥综合| 国内精品久久久久久野外| 久久久亚洲裙底偷窥综合| 欧美日韩中文字幕久久久不卡 | 奇米影视7777久久精品| 久久精品国产亚洲5555| 久久91精品国产91久久户| 久久无码人妻一区二区三区| 麻豆精品久久久久久久99蜜桃| 精品视频久久久久| AA级片免费看视频久久| 欧美久久精品一级c片片| MM131亚洲国产美女久久| 色偷偷88888欧美精品久久久| 精品国产乱码久久久久软件| 欧美精品一区二区久久| 久久精品国产亚洲一区二区三区| 久久青青草原国产精品免费| 国产精品久久久久9999| 色婷婷久久综合中文久久蜜桃av | 无码人妻久久一区二区三区免费 | 久久国产高清字幕中文| 久久精品这里热有精品| 94久久国产乱子伦精品免费| 久久无码av三级| 久久久精品久久久久久| 香蕉久久永久视频| 亚洲综合日韩久久成人AV| 久久国产色AV免费看| 久久久91精品国产一区二区三区 | 精品国产乱码久久久久软件|