Dungeon Master
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 24311   Accepted: 9425

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!
题目链接:poj2251

/*题目大意:l,r,c。表示l层,r行,c列。从起点s到终点e的最小步数、其中.为通道,#为墙。只能上下左右走,也能从上一层跳到相对应的下一层
算法分析:三维bfs搜索
坑点:每次处理完后要清空队列中所有元素
*/ #include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std; int L, R, C;
int vis[40][40][40];
int l[6] = {1, -1, 0, 0, 0, 0}, r[6] = {0, 0, 1, -1, 0, 0}, c[6] = {0, 0, 0, 0, 1, -1};
char map[40][40][40];
struct node {
int z, x, y;
int time;
}; node start, end;
queue <node> q; int judge(int a, int b, int c) {
if (a>=0 && a<L && b>=0 && b<R && c>=0 && c<C) return 1;
return 0;
} int dfs() { while (!q.empty()) {
node cur, next;
cur = q.front();
q.pop();
if (cur.z == end.z && cur.x == end.x && cur.y == end.y && judge(cur.z,cur.x,cur.y)) return cur.time;
for (int i = 0; i<6; i++) {
next.z = cur.z + l[i];
next.x = cur.x + r[i];
next.y = cur.y + c[i];
next.time = cur.time + 1;
if (judge(next.z, next.x, next.y) && map[next.z][next.x][next.y] != '#' && !vis[next.z][next.x][next.y]) {
if (next.z == end.z && next.x == end.x && next.y == end.y) return next.time;
q.push(next);
vis[next.z][next.x][next.y] = 1;
}
}
}
return -1;
} int main() {
while (cin >> L >> R >> C && (L+R+C)) {
memset(map, 0, sizeof(map));
memset(vis, 0, sizeof(vis)); for (int i = 0; i<L; i++) {
for (int j = 0; j<R; j++) {
for (int k = 0; k<C; k++) {
cin >> map[i][j][k];
if (map[i][j][k] == 'S') {
start.z = i;
start.x = j;
start.y = k;
start.time = 0;
vis[i][j][k] = 1;
q.push(start);
}
else if (map[i][j][k] == 'E') {
end.z = i;
end.x = j;
end.y = k;
}
}
}
}
int ans = dfs();
if (ans == -1) cout << "Trapped!" << endl;
else cout << "Escaped in " << ans << " minute(s)."<< endl;
while (!q.empty()) q.pop();
}
return 0;
}

poj_2251的更多相关文章

随机推荐

  1. 关于ubuntu下qt编译显示Cannot connect creator comm socket /tmp/qt_temp.xxx/stub-socket的解决办法

    今天在ubuntu下安装了qtcreator,准备测试一下是否能用,果然一测试就出问题了,简单编写后F5编译在gnome-terminal中出现 Cannot connect creator comm ...

  2. 通过 JS 实现简单的拖拽功能并且可以在特定元素上禁止拖拽

    前言 关于讲解 JS 的拖拽功能的文章数不胜数,我确实没有必要大费周章再写一篇重复的文章来吸引眼球.本文的重点是讲解如何在某些特定的元素上禁止拖拽.这是我在编写插件时遇到的问题,其实很多插件的拖拽功能 ...

  3. jstree 学习

    最近的项目用到了jstree,因为对官方文档理解不充分,所以很多功能都是在网站上搜索再进行使用的.(我只是大自然的搬运工) 对每一级的节点,右键后出现不同的结果. 在jstree中右键是由 conte ...

  4. Python学习(五):易忘知识点

    1.列表比较函数cmp >>> a = [1,2,3,4] >>> b = [1,2,3,4,5] >>> c = [1,2,3,4] >& ...

  5. 理解Kubernetes(1):手工搭建Kubernetes测试环境

    系列文章: 1. 手工搭建环境 1. 基础环境准备 准备 3个Ubuntu节点,操作系统版本为 16.04,并做好以下配置: 系统升级 设置 /etc/hosts 文件,保持一致 设置从 0 节点上无 ...

  6. Hello TensorFlow 二 (GPU)

    官方说明:https://www.tensorflow.org/install/ 环境: 操作系统 :Windows 10 家庭中文版 处理器 : Intel(R) Core(TM) i7-7700 ...

  7. WebSocket协议:5分钟从入门到精通

    一.内容概览 WebSocket的出现,使得浏览器具备了实时双向通信的能力.本文由浅入深,介绍了WebSocket如何建立连接.交换数据的细节,以及数据帧的格式.此外,还简要介绍了针对WebSocke ...

  8. 这些年常用的WEB开发工具和技术, 学会一半你找工作没问题

    前言: 技术选型并不是一成不变的,需要根据技术的发展.项目实际情况和人员技能构成实际考虑,在此列出的只是这些年常用的. 开发环境 1. 主要开发语言:Java7, HTML, Javascript等 ...

  9. Head First设计模式之组合模式

    一.定义 将对象组合成树形结构来表现"整体-部分"层次结构. 组合能让客户以一致的方法处理个别对象以及组合对象. 主要部分可以被一致对待问题. 在使用组合模式中需要注意一点也是组合 ...

  10. Python新式类与经典类的区别

    1.新式类与经典类 在Python 2及以前的版本中,由任意内置类型派生出的类(只要一个内置类型位于类树的某个位置),都属于“新式类”,都会获得所有“新式类”的特性:反之,即不由任意内置类型派生出的类 ...