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

            9191精品国产免费久久| 久久强奷乱码老熟女| 2021国内久久精品| 久久棈精品久久久久久噜噜| 国产精品青草久久久久婷婷| 精品一久久香蕉国产线看播放 | 亚洲国产另类久久久精品黑人| 亚洲国产精品18久久久久久| 国产精品热久久毛片| 亚洲欧美另类日本久久国产真实乱对白 | 国内精品久久久久久99蜜桃| 久久精品国产亚洲av瑜伽| 亚洲精品无码久久一线| 狠狠综合久久综合中文88| 人妻久久久一区二区三区| 中文字幕无码久久人妻| 久久99久久无码毛片一区二区| 久久无码人妻一区二区三区 | 亚洲精品乱码久久久久久中文字幕| 草草久久久无码国产专区| 久久99国产综合精品| 亚洲国产另类久久久精品小说| 久久久久久久久久免免费精品| 色综合久久综合网观看| 久久精品无码专区免费青青| 伊人久久大香线蕉综合Av | 熟妇人妻久久中文字幕| 亚洲乱码中文字幕久久孕妇黑人| 中文字幕久久亚洲一区| 尹人香蕉久久99天天拍| 久久人人爽人人爽人人av东京热| 欧美久久综合九色综合| 欧美日韩精品久久久久| 亚洲精品无码久久不卡| 久久大香萑太香蕉av| 婷婷国产天堂久久综合五月| 亚洲人成网站999久久久综合| 无码国内精品久久人妻麻豆按摩 | 97视频久久久| 欧美喷潮久久久XXXXx| 久久精品亚洲日本波多野结衣|