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

            poj2251

            Dungeon Master

            Time Limit: 1000MS Memory Limit: 65536K
            Total Submissions: 10668 Accepted: 4111

            Description

            You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.

            Is an escape possible? If yes, how long will it take?

            Input

            The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
            L is the number of levels making up the dungeon.
            R and C are the number of rows and columns making up the plan of each level.
            Then there will follow L blocks of R lines each containing C characters. Each character describes one cell of the dungeon. A cell full of rock is indicated by a '#' and empty cells are represented by a '.'. Your starting position is indicated by 'S' and the exit by the letter 'E'. There's a single blank line after each level. Input is terminated by three zeroes for L, R and C.

            Output

            Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
            Escaped in x minute(s).

            where x is replaced by the shortest time it takes to escape.
            If it is not possible to escape, print the line
            Trapped!

            Sample Input

            3 4 5
            S....
            .###.
            .##..
            ###.#
            
            #####
            #####
            ##.##
            ##...
            
            #####
            #####
            #.###
            ####E
            
            1 3 3
            S##
            #E#
            ###
            
            0 0 0
            

            Sample Output

            Escaped in 11 minute(s).
            Trapped!
            
            這題不難,廣搜,不知道為什么這個(gè)題目在那個(gè)指導(dǎo)中出現(xiàn)在dfs中
            代碼也好些,就是floodfill,往六個(gè)方向搜,如果已經(jīng)走過(guò)則不走,如果沒(méi)走過(guò)且能走則走
            這次數(shù)組開(kāi)小了,第一次隊(duì)列開(kāi)了1000,不知道怎么想的
            第二次檢查 改成10000了,然后還是wa
            第三次 改成100000,終于過(guò)了
             1#include<stdio.h>
             2#include<string.h>
             3#include<math.h>
             4struct node
             5{
             6    int x,y,z,d;
             7}
            ;
             8int dx[6][3]= {{1,0,0},{-1,0,0},{0,1,0},{0,-1,0},{0,0,1},{0,0,-1}};
             9int l,r,c,sum,ans,head,tail;
            10struct node que[100000],ss,tt;
            11short hash[35][35][35];
            12char map[35][35][35];
            13void bfs()
            14{
            15    int i,j;
            16    struct node now,new1;
            17    ans=0;
            18    head=0;
            19    tail=1;
            20    que[tail]=ss;
            21    memset(hash,0,sizeof(hash));
            22    hash[ss.x][ss.y][ss.z]=1;
            23    while (head<tail)
            24    {
            25        head++;
            26        now=que[head];
            27        /*if (now.x==tt.x&&now.y==tt.y&&now.z==tt.z)
            28        {
            29            ans=now.d;
            30            return;
            31        }*/

            32        for (i=0; i<6 ; i++ )
            33        {
            34            new1.x=now.x+dx[i][0];
            35            new1.y=now.y+dx[i][1];
            36            new1.z=now.z+dx[i][2];
            37            new1.d=now.d+1;
            38            if (new1.x>=0&&new1.x<l&&new1.y>=0&&new1.y<r&&new1.z>=0&&new1.z<c)//未越界
            39                if ((map[new1.x][new1.y][new1.z]!='#')&&(!hash[new1.x][new1.y][new1.z]))//能走且未走過(guò)
            40                {
            41                    if (map[new1.x][new1.y][new1.z]=='E')
            42                    {
            43                        ans=new1.d;
            44                        return;
            45                    }

            46                    if (!hash[new1.x][new1.y][new1.z])
            47                    {
            48                        tail++;
            49                        que[tail]=new1;
            50                        hash[new1.x][new1.y][new1.z]=1;
            51                    }

            52                }

            53        }

            54    }

            55}

            56void init()
            57{
            58    int i,j,k;
            59    for (i=0; i<l; i++ )
            60    {
            61        for (j=0; j<r ; j++ )
            62        {
            63            scanf("%s",&map[i][j]);
            64            for (k=0; k<c ; k++ )
            65            {
            66                if (map[i][j][k]=='S')
            67                {
            68                    ss.x=i;
            69                    ss.y=j;
            70                    ss.z=k;
            71                    ss.d=0;
            72                }

            73                if (map[i][j][k]=='E')
            74                {
            75                    tt.x=i;
            76                    tt.y=j;
            77                    tt.z=k;
            78                }

            79            }

            80        }

            81    }

            82}

            83int main()
            84{
            85    while (scanf("%d%d%d",&l,&r,&c)!=EOF&&!(l==0&&r==0&&c==0))
            86    {
            87        init();
            88        bfs();
            89        if (ans==0)
            90        {
            91            printf("Trapped!\n");
            92        }

            93        else
            94            printf("Escaped in %d minute(s).\n",ans);
            95    }

            96    return 0;
            97}

            98

            posted on 2012-02-24 13:13 jh818012 閱讀(220) 評(píng)論(0)  編輯 收藏 引用


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


            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章檔案(85)

            搜索

            最新評(píng)論

            • 1.?re: poj1426
            • 我嚓,,輝哥,,居然搜到你的題解了
            • --season
            • 2.?re: poj3083
            • @王私江
              (8+i)&3 相當(dāng)于是 取余3的意思 因?yàn)?3 的 二進(jìn)制是 000011 和(8+i)
            • --游客
            • 3.?re: poj3414[未登錄](méi)
            • @王私江
              0ms
            • --jh818012
            • 4.?re: poj3414
            • 200+行,跑了多少ms呢?我的130+行哦,你菜啦,哈哈。
            • --王私江
            • 5.?re: poj1426
            • 評(píng)論內(nèi)容較長(zhǎng),點(diǎn)擊標(biāo)題查看
            • --王私江
            思思久久99热只有频精品66| 久久婷婷五月综合97色直播| 久久久久久久波多野结衣高潮 | 久久久久久免费一区二区三区| 香蕉久久夜色精品国产尤物| 国产亚洲成人久久| 久久国产乱子精品免费女| 久久亚洲精品成人av无码网站| 久久天天躁狠狠躁夜夜不卡| 青青久久精品国产免费看| 国产高清国内精品福利99久久| www久久久天天com| 69久久精品无码一区二区| 国内精品久久久久影院优| 久久精品无码一区二区无码| 亚洲va久久久噜噜噜久久男同| 久久婷婷国产剧情内射白浆| 亚洲狠狠婷婷综合久久久久| 亚洲日本va中文字幕久久| 久久久老熟女一区二区三区| 久久成人国产精品| 99国产欧美久久久精品蜜芽| 久久se精品一区二区| 99久久精品免费看国产一区二区三区| 青青青青久久精品国产| 亚洲综合精品香蕉久久网97 | 久久se精品一区二区影院| 久久e热在这里只有国产中文精品99 | 久久av高潮av无码av喷吹| 一本久久a久久精品综合香蕉| 久久婷婷五月综合成人D啪| 亚洲国产另类久久久精品小说| 亚洲午夜久久久久妓女影院 | 国产成人无码精品久久久久免费| 久久精品中文字幕第23页| 久久综合久久美利坚合众国| 久久久精品人妻一区二区三区四 | 国产69精品久久久久99| 欧美精品丝袜久久久中文字幕| 精品久久久久久中文字幕大豆网| 久久久久AV综合网成人|