#include#includeusingnamespacestd;constintMAXN=50;charstr[MAXN][MAXN][MAXN];intstep[MAXN][MAXN][MAXN];intvis[MAXN][MAXN][MAXN];intl,r,c;structNode{intx,y,z;}s,e;intB" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

poj 2251 Dungeon Master(廣搜)

系統(tǒng) 2300 0

題意:三維空間,可以走上下左右前后六個(gè)方向,求最短路徑,BFS

??

      #include<stdio.h>
      
        

#include
      
      <queue>
      
        

#include
      
      <
      
        string
      
      .h>


      
        using
      
      
        namespace
      
      
         std;


      
      
        const
      
      
        int
      
       MAXN=
      
        50
      
      
        ;




      
      
        char
      
      
         str[MAXN][MAXN][MAXN];


      
      
        int
      
      
         step[MAXN][MAXN][MAXN];


      
      
        int
      
      
         vis[MAXN][MAXN][MAXN];


      
      
        int
      
      
         l,r,c;


      
      
        struct
      
      
         Node

{

    
      
      
        int
      
      
         x,y,z;

}s,e;




      
      
        int
      
      
         BFS()

{

    
      
      
        int
      
      
         i,j;

    Node head,next;

    queue
      
      <Node>
      
        Q;

    Q.push(s);

    step[s.x][s.y][s.z]
      
      =
      
        0
      
      
        ;

    
      
      
        while
      
      (!
      
        Q.empty())

    {

        head
      
      =
      
        Q.front();

        Q.pop();

        
      
      
        for
      
      (i=
      
        0
      
      ;i<
      
        6
      
      ;i++
      
        )

        {

            next
      
      =
      
        head;

            
      
      
        if
      
      (i==
      
        0
      
      ) next.x-=
      
        1
      
      
        ;

            
      
      
        if
      
      (i==
      
        1
      
      ) next.x+=
      
        1
      
      
        ;

            
      
      
        if
      
      (i==
      
        2
      
      ) next.y-=
      
        1
      
      
        ;

            
      
      
        if
      
      (i==
      
        3
      
      ) next.y+=
      
        1
      
      
        ;

            
      
      
        if
      
      (i==
      
        4
      
      ) next.z-=
      
        1
      
      
        ;

            
      
      
        if
      
      (i==
      
        5
      
      ) next.z+=
      
        1
      
      
        ;

            
      
      
        if
      
      (!vis[next.x][next.y][next.z] && str[next.x][next.y][next.z]==
      
        1
      
      
        )

            {

                vis[next.x][next.y][next.z]
      
      =
      
        1
      
      
        ;

                Q.push(next);

                step[next.x][next.y][next.z]
      
      =step[head.x][head.y][head.z]+
      
        1
      
      
        ;

                
      
      
        if
      
      (next.x==e.x && next.y==e.y && next.z==e.z) 
      
        return
      
        step[head.x][head.y][head.z]+
      
        1
      
      
        ;

            }

        }

    }

    
      
      
        return
      
      
        0
      
      
        ;

}


      
      
        int
      
      
         main()

{

    
      
      
        int
      
      
         i,j,k;

    
      
      
        while
      
      (scanf(
      
        "
      
      
        %d%d%d
      
      
        "
      
      ,&l,&r,&c)!=
      
        EOF)

    {

        
      
      
        if
      
      (l==
      
        0
      
       && r==
      
        0
      
       && c==
      
        0
      
      ) 
      
        break
      
      
        ;

        memset(vis,
      
      
        0
      
      ,
      
        sizeof
      
      
        (vis));

        memset(str,
      
      
        0
      
      ,
      
        sizeof
      
      
        (str));

        
      
      
        for
      
      (i=
      
        1
      
      ; i<=l; i++
      
        )

        {

            
      
      
        for
      
      (j=
      
        1
      
      ; j<=r; j++
      
        )

            {

                scanf(
      
      
        "
      
      
        %s
      
      
        "
      
      ,str[i][j]+
      
        1
      
      
        );

                
      
      
        for
      
      (k=
      
        1
      
      ; str[i][j][k]; k++
      
        )

                {

                    
      
      
        if
      
      (str[i][j][k]==
      
        '
      
      
        #
      
      
        '
      
      ) str[i][j][k]=
      
        0
      
      
        ;

                    
      
      
        if
      
      (str[i][j][k]==
      
        '
      
      
        .
      
      
        '
      
      ) str[i][j][k]=
      
        1
      
      
        ;

                    
      
      
        if
      
      (str[i][j][k]==
      
        '
      
      
        S
      
      
        '
      
      
        )

                    {

                        str[i][j][k]
      
      =
      
        1
      
      
        ;

                        s.x
      
      =
      
        i;

                        s.y
      
      =
      
        j;

                        s.z
      
      =
      
        k;

                    }

                    
      
      
        if
      
      (str[i][j][k]==
      
        '
      
      
        E
      
      
        '
      
      
        )

                    {

                        str[i][j][k]
      
      =
      
        1
      
      
        ;

                        e.x
      
      =
      
        i;

                        e.y
      
      =
      
        j;

                        e.z
      
      =
      
        k;

                    }

                }

            }

        }

        
      
      
        int
      
       ans=
      
        BFS();

        
      
      
        if
      
      (ans) printf(
      
        "
      
      
        Escaped in %d minute(s).\n
      
      
        "
      
      
        ,ans);

        
      
      
        else
      
       printf(
      
        "
      
      
        Trapped!\n
      
      
        "
      
      
        );



    }

    
      
      
        return
      
      
        0
      
      
        ;

}
      
    

?

poj 2251 Dungeon Master(廣搜)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫(xiě)作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 千阳县| 昌吉市| 池州市| 临邑县| 宝兴县| 徐水县| 湖州市| 新建县| 儋州市| 兴城市| 江口县| 黔西| 璧山县| 四子王旗| 儋州市| 民县| 邹平县| 靖远县| 齐齐哈尔市| 旺苍县| 牟定县| 迁西县| 公主岭市| 成都市| 固阳县| 大石桥市| 怀宁县| 通许县| 江阴市| 正镶白旗| 昔阳县| 策勒县| 卓尼县| 贵定县| 高州市| 平乡县| 临沂市| 台安县| 亚东县| 出国| 那坡县|