• <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   管理


            亚洲成色WWW久久网站| 国产国产成人精品久久| 久久中文字幕人妻丝袜| 亚洲va久久久噜噜噜久久男同| 99久久国产热无码精品免费| 久久久网中文字幕| 97精品伊人久久大香线蕉app| 久久久黄片| 九九久久自然熟的香蕉图片| 日韩久久久久中文字幕人妻| 国产情侣久久久久aⅴ免费| 久久久精品波多野结衣| 亚洲AV无码久久| 亚洲精品第一综合99久久| 国产成人精品久久免费动漫| 亚洲中文久久精品无码ww16| 久久亚洲电影| 久久久久99精品成人片| 日本三级久久网| 青青草国产成人久久91网| 亚洲AV无一区二区三区久久| 性做久久久久久免费观看| 久久综合九色综合欧美狠狠| 日韩精品久久久久久免费| 亚洲第一极品精品无码久久| 日本WV一本一道久久香蕉| 亚洲欧美另类日本久久国产真实乱对白 | 久久久久国产精品人妻| 久久久亚洲精品蜜桃臀| 国产精品VIDEOSSEX久久发布| 久久99精品国产麻豆宅宅 | 国产色综合久久无码有码| 亚洲?V乱码久久精品蜜桃 | 人妻无码久久精品| 思思久久99热免费精品6| 久久久久国产精品人妻| 久久综合给久久狠狠97色| 99久久国产综合精品麻豆| 久久久青草青青亚洲国产免观| 国产精品福利一区二区久久| 久久福利青草精品资源站免费|