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. Mybatis-----优化配置文件,基于注解CR

    这篇主要写配置文件的优化,例如  jdbc.properties 配置文件  ,引入数据库的文件,例如driver,url,username,password 等,然后在 SqlMapConfig.x ...

  2. C#打印杨辉三角

    重主要的方法在于: 1.初始化二维数组 2.边界赋值 3.中心值赋值 4.输出 <pre name="code" class="csharp"> c ...

  3. JAVA NIO学习二:通道(Channel)与缓冲区(Buffer)

    今天是2018年的第三天,真是时光飞逝,2017年的学习计划还没有学习完成,因此继续开始研究学习,那么上一节我们了解了NIO,那么这一节我们进一步来学习NIO相关的知识.那就是通道和缓冲区.Java ...

  4. Linux第八讲随笔 -tar / 系统启动流程

    linux 第八讲1.tar 参考 作用:压缩和解压文件.tar本身不具有压缩功能.他是调用压缩功能实现的. 语法:tar[必要参数][选择参数][文件] 参数:必要参数有如下: -A 新增压缩文件到 ...

  5. weex Mac开发环境

    安装: 1.java的jdk下载和安装 1-1.下载.安装:省略 1-2.配置 第一步:命令行内输入touch .bash_profile命令,生成.bash_profile的隐藏配置文件,用于配置j ...

  6. php+中文分词scws+sphinx+mysql打造千万级数据全文搜索

    转载自:http://blog.csdn.net/nuli888/article/details/51892776 Sphinx是由俄罗斯人Andrew Aksyonoff开发的一个全文检索引擎.意图 ...

  7. 浅谈JavaScript的面向对象程序设计(一)

    面向对象的语言有一个标志,他们都有类的概念,通过类可以创建多个具有相同属性和方法的对象.但是JavaScript中没有类的概念,因此JavaScript与其他的面向对象语言还是有一定区别的.JavaS ...

  8. Vuex- Action的 { commit }

    Vuex 中 使用 Action 处理异步请求时,常规写法如下: getMenuAction:(context) =>{ context.commit('SET_MENU_LIST',['承保2 ...

  9. Lucene.net(4.8.0) 学习问题记录二: 分词器Analyzer中的TokenStream和AttributeSource

    前言:目前自己在做使用Lucene.net和PanGu分词实现全文检索的工作,不过自己是把别人做好的项目进行迁移.因为项目整体要迁移到ASP.NET Core 2.0版本,而Lucene使用的版本是3 ...

  10. webpack 构建简单的vue项目

    ---恢复内容开始--- webpack主要执行流程: 入口→loader处理→出口 // webpack.config.js 文件:const path = require('path') // 引 ...