Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 17555   Accepted: 6835

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

 
bfs 六个方向直接乱搞就好
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 31
const int inf=0x7fffffff; //无限大
int visited[maxn][maxn][maxn];
struct node
{
int x;
int y;
int z;
int cnt;
};
int dx[]={,-,,,,};
int dy[]={,,,-,,};
int dz[]={,,,,,-};
int main()
{
int n,m,k;
string s;
while(cin>>n>>m>>k)
{
if(n==&&m==&&k==)
break;
memset(visited,,sizeof(visited));
node sb;
node sb2;
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
cin>>s;
for(int t=;t<k;t++)
{
if(s[t]=='S')
{
sb.x=i;
sb.y=j;
sb.z=t;
sb.cnt=;
}
if(s[t]=='E')
{
sb2.x=i;
sb2.y=j;
sb2.z=t;
}
if(s[t]=='#')
{
visited[i][j][t]=;
}
}
}
}
queue<node> q;
q.push(sb);
visited[sb.x][sb.y][sb.z]=;
int flag=;
while(!q.empty())
{
node now=q.front();
for(int i=;i<;i++)
{
node next;
next.x=now.x+dx[i];
next.y=now.y+dy[i];
next.z=now.z+dz[i];
next.cnt=now.cnt+;
if(next.x<||next.x>=n||next.y<||next.y>=m||next.z<||next.z>=k)
continue;
if(visited[next.x][next.y][next.z])
continue;
visited[next.x][next.y][next.z]=;
if(next.x==sb2.x&&next.y==sb2.y&&next.z==sb2.z)
flag=next.cnt;
if(flag>)
break;
q.push(next);
}
if(flag>)
break;
q.pop();
}
if(flag>)
printf("Escaped in %d minute(s).\n",flag);
else
cout<<"Trapped!"<<endl; }
return ;
}

hdu 2251 Dungeon Master bfs的更多相关文章

  1. poj 2251 Dungeon Master( bfs )

    题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A,     上代码 #include <iostream> #include<cst ...

  2. poj 2251 Dungeon Master (BFS 三维)

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

  3. POJ 2251 Dungeon Master bfs 难度:0

    http://poj.org/problem?id=2251 bfs,把两维换成三维,但是30*30*30=9e3的空间时间复杂度仍然足以承受 #include <cstdio> #inc ...

  4. POJ 2251 Dungeon Master (BFS最短路)

    三维空间里BFS最短路 #include <iostream> #include <cstdio> #include <cstring> #include < ...

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

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

  6. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  7. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  8. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  9. poj 2251 Dungeon Master

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

随机推荐

  1. Splay算法摘要

    先介绍变量定义 int n; struct Node { //Splay节点定义 ],val,num,siz; //fa:它爸爸:son它儿子,左0右1:val:这个节点的值 //num:这个值的数量 ...

  2. Bootstrap FileInput 多图上传插件 文档属性说明

    Bootstrap FileInput 多图上传插件   原文链接:http://blog.csdn.net/misterwho/article/details/72886248?utm_source ...

  3. 网络路径查询traceroute

    Traceroute用法   网友:适兕 发布于: 2006.08.24 08:14 (共有条评论) 查看评论 | 我要评论   一.什么是Traceroute?                 In ...

  4. mysql数据库主从同步复制原理

    MySQL的Replication(英文为复制)是一个多MySQL数据库做主从同步的方案,特点是异步复制,广泛用在各种对MySQL有更高性能.更高可靠性要求的场合.与之对应的是另一个同步技术是MySQ ...

  5. Java事务管理之Spring+Hibernate

    环境与版本 除了上一篇中的hibernate的相关lib 外 Java事务管理之Hibernate 还需要加入Spring的lib 包和如下的一些依赖包 org.aopallianceorg.aspe ...

  6. 一张图来帮你理解 SOA

    SOA 曾经一度是技术领域中最难以理解的一个概念.SOA 似乎让很多人感到困惑 - 一般来讲这是由于人们认为它拥有几乎神奇的力量.事实上 SOA 只是一个很简单的概念:SOA 由诸如 C++ 和 Ja ...

  7. C# POS 小票打印

    网上查了好多资料终于让我捣鼓出来了! public partial class Models_JXC_Sale_actNewSalePage : WebPartBase { public string ...

  8. Java实现统计某字符串在另一个字符串中出现的次数

    面试时会经常考这样的题目,估计也不让使用正则表达式.还好这个算法还算简单,不过在草稿纸上写难免会出现运行异常,好吧,面试官赢了,乃们屌丝就实实在在的把代码码出来吧. 谢谢“心扉”对我代码bug的纠正, ...

  9. 007 Ajax中的购物车

    1.大纲设计 2.shopingCartItem.java package beans; public class shopingCartItem { private String bookname; ...

  10. 远程连接mysql root账号报错:2003-can't connect to MYSQL serve

    1.远程连接Linux系统,登录数据库:mysql -uroot -p(密码) 2.修改root账号的设置: GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDE ...