Language:
Default
Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 16855   Accepted: 6564

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!

Source

题意:给你一个三维迷宫。从起点到终点求最短步数。

思路:和二维的迷宫问题差点儿相同,略微改成三维的即可了。

代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>
using namespace std; struct Node
{
int x,y,z;
int step;
}; char mp[35][35][35];
int visit[35][35][35];
int dir[6][3]={-1,0,0,1,0,0,0,-1,0,0,1,0,0,0,1,0,0,-1};//x,y,z
int N,M,P,sx,sy,sz,ex,ey,ez; bool ISok(int x,int y,int z)
{
if (z>=0&&z<P&&x>=0&&x<N&&y>=0&&y<M&&mp[z][x][y]!='#'&&!visit[z][x][y])
return true;
return false;
} void bfs()
{
Node st,now;
memset(visit,0,sizeof(visit));
queue<Node>Q;
visit[sz][sx][sy]=1;
st.x=sx;st.y=sy;st.z=sz;
st.step=0;
Q.push(st);
while (!Q.empty())
{
st=Q.front();
Q.pop();
if (st.x==ex&&st.y==ey&&st.z==ez)
{
printf("Escaped in %d minute(s).\n",st.step);
return ;
}
for (int i=0;i<6;i++)
{
now.x=st.x+dir[i][0];
now.y=st.y+dir[i][1];
now.z=st.z+dir[i][2];
if (ISok(now.x,now.y,now.z))
{
now.step=st.step+1;
visit[now.z][now.x][now.y]=1;
Q.push(now);
}
}
}
printf("Trapped!\n");
return ;
} int main()
{
while (scanf("%d%d%d",&P,&N,&M)&&P)
{
for (int i=0;i<P;i++)
{
for (int j=0;j<N;j++)
{
scanf("%s",mp[i][j]);//z,x,y
for (int t=0;t<M;t++)
{
if (mp[i][j][t]=='S')
{
sx=j;sy=t;sz=i;
}
if (mp[i][j][t]=='E')
{
ex=j;ey=t;ez=i;
}
}
}
}
bfs();
}
return 0;
}

版权声明:本文博主原创文章,博客,未经同意不得转载。

Dungeon Master poj 2251 dfs的更多相关文章

  1. Dungeon Master POJ - 2251 (搜索)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 48605   Accepted: 18339 ...

  2. (广搜)Dungeon Master -- poj -- 2251

    链接: http://poj.org/problem?id=2251 Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2137 ...

  3. Dungeon Master POJ - 2251(bfs)

    对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...

  4. Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索

    You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...

  5. B - Dungeon Master POJ - 2251

    //纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...

  6. kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251

    题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...

  7. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  8. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  9. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

随机推荐

  1. UVALive 6469 Deranged Exams (排列:力绝对是无辜的高中知识啊)

    标题手段 : 给你个n([1,17])表达n无论从数据结构.然后n个对这些术语的定义,让你对这些术语和定义对号入座(相当于进行连线,A术语连A术语的定义).然后一个 k([0,n]).问你至少前k个术 ...

  2. jQuery Mobile发展新闻阅读器,适应iphone和android打电话

    程序猿是很不赖,你知道. 我们经常新浪,腾讯.雅虎等各大网站看到上述新闻.他们还推出了自己的移动新闻阅读器.今天,我自己用的jQuery Mobile 为了实现这一功能,.图像大小上传限制的大小250 ...

  3. Lock_sga 和 pre_page_sga 参数详解

    Lock_sga 和 pre_page_sga 参数详解        Lock_sga 和pre_page_sga,是两个平时用的不算太多的参数,但是这两个参数平时在优化的时候可能给你带来比较乐观的 ...

  4. Java TCP/UDP网络通信编程

    本文转自:http://www.cnblogs.com/cdtarena/archive/2013/04/10/3012282.html 网络应用中基本上都是TCP(Transmission Cont ...

  5. HTML5 transform三维立方体(随着旋转的效果)

    为了得到更好的把握transform精华.因此,我们决定完成三维立方体模型,可以实现360无死三维旋转作用. 但旋转更难推断每侧视图的序列.然而,完美的解决方案,我希望有人能回答. 源代码直接贡献的朋 ...

  6. java_访问权限修饰符

    java的访问权限修饰符有四种,根据权限由大到小的顺序为:public,protected,包访问权限(默认,没有修饰符),private. 根据修饰的东西不同,详细介绍如下: 1.修饰类的话分为两种 ...

  7. MapReduce架构和算法(2)

    一个.combiner计划 每map它可能会产生大量的输出,combiner的作用是map输出端先做合并.reducer的数据量. combiner最基本是实现本地key的归并,combiner具有类 ...

  8. GMSK调制仿真

    GMSK 调制的的原理非常简单. 就是MSK调制前进行Gauss滤波. 在实现中有这样的方法,首先产生高斯系数,对称的上升陂和下降陂系数.输入一个符号,进行上采样,经过高斯滤波器,滤波器的输出做有符号 ...

  9. Cordic 算法之 反正切

    在通信的算法中,常采用Cordic算法之一,知道角度产生正交的的正弦余弦, 或者知道正弦和余弦求角度,求反正切. 1. 求正弦和余弦值. 方法:旋转角度,得到正弦余弦值: 再旋转角度,到达下一个正弦余 ...

  10. php形式的内容被处理

    /** * 过滤HTML内容RETURN * * @param $string * @param bool $html * * @return array|string */ public stati ...