Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21242   Accepted: 8265

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!
三维BFS 注意xyz别弄混了
/* ***********************************************
Author :pk29
Created Time :2015/8/19 18:40:40
File Name :4.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10000+10
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
struct node{
int x,y,z;
int dist;
};
bool cmp(int a,int b){
return a>b;
}
int l,r,c;
char mp[][][];
int vis[][][];
int sx,sy,sz,ex,ey,ez;
int dir[][]={,,,,,,,,-,,,,-,,,,-,}; void bfs(){
node u,v;
u.x=sx,u.y=sy,u.z=sz, u.dist=;
queue<node>q;
q.push(u);
int mark=;
vis[u.x][u.y][u.z]=;
while(!q.empty()){
u=q.front(),q.pop();
if(u.x==ex&&u.y==ey&&u.z==ez){
mark=;printf("Escaped in %d minute(s).\n",u.dist);break;
}
for(int i=;i<;i++){
int nx=u.x+dir[i][];
int ny=u.y+dir[i][];
int nz=u.z+dir[i][];
if(!vis[nx][ny][nz]&&mp[nx][ny][nz]!='#'&&nx>=&&ny>=&&nz>=&&nx<=r&&ny<=c&&nz<=l){
v.x=nx,v.y=ny,v.z=nz;
v.dist=u.dist+;
q.push(v);
vis[nx][ny][nz]=;
}
}
}
if(!mark)printf("Trapped!\n");
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
while(cin>>l>>r>>c){
if(l==&&c==&&r==)break;
for(int i=;i<=l;i++)
for(int j=;j<=r;j++)
for(int k=;k<=c;k++){
cin>>mp[j][k][i];
if(mp[j][k][i]=='S')sx=j,sy=k,sz=i;
if(mp[j][k][i]=='E')ex=j,ey=k,ez=i;
}
cle(vis);
//cout<<sx<<sy<<sz<<endl;
//cout<<ex<<ey<<ez<<endl; bfs();
}
return ;
}

POJ 3279 Dungeon Master的更多相关文章

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

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

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

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

  3. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

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

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

  5. BFS POJ 2251 Dungeon Master

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

  6. poj 2251 Dungeon Master

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

  7. POJ 2251 Dungeon Master (三维BFS)

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

  8. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. 【leetcode】lower_bound

    int binary_search(const vector<int>& stones,int val){ int sz=stones.size(); ,r=sz-; while( ...

  2. 【离散化树状数组】Nordic Collegiate Programming Contest G.Galactic Collegiate Programming Contest

    #include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; ; struct node { in ...

  3. 转载:hmm学习网站

    http://www.52nlp.cn/hmm-learn-best-practices-seven-forward-backward-algorithm-5

  4. Garbage First介绍

    本文摘自<构建高性能的大型分布式Java应用>一书,Garbage First简称G1,它的目标是要做到尽量减少GC所导致的应用暂停的时间,让应用达到准实时的效果,同时保持JVM堆空间的利 ...

  5. STL学习笔记(三) 关联容器

    条款19:理解相等(equality)和等价(equivalence)的区别 相等的概念是基于 operator== 的,如果 operator== 的实现不正确,会导致并不实际相等等价关系是以&qu ...

  6. jQuery事件委托之Safari失效的解决办法--摘抄

    什么是事件委托 事件委托是Jquery中一种事件绑定的方式,不同于常见的事件绑定方式将事件绑定在目标元素上,而是将事件绑定在父级元素上通过事件冒泡来执行绑定函数. //常见的事件绑定(Jquery) ...

  7. 转 STL之vector的使用

    http://www.cnblogs.com/caoshenghe/archive/2010/01/31/1660399.html 第一部分 使用入门 vector可用于代替C中的数组,或者MFC中的 ...

  8. Day 10 Linux nfs && crond(摘)

    (摘) 介绍: NFS 是Network File System的缩写,即网络文件系统.一种使用于分散式文件系统的协定,由Sun公司开发,于1984年向外公布.功能是通过网络让不同的机器.不同的操作系 ...

  9. android:logo

    <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="ht ...

  10. [转]JVM 堆内存设置原理

    堆内存设置 原理 JVM堆内存分为2块:Permanent Space 和 Heap Space. Permanent 即 持久代(Permanent Generation),主要存放的是Java类定 ...