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. MongoDB入门系列(二):Insert、Update、Delete、Drop

    概述 本章节介绍Insert.Update.Delete.Drop操作基本语法. 环境: Version:3.4 insert insert()基本语法如下: db.collection.insert ...

  2. mysql-5.7.17.msi安装

    mysql-5.7.17.msi安装,跟着截图摩擦,一步一步是爪牙,是魔鬼的步伐 开始: 可以创建其他用户 我自己改了日志名

  3. JPA实体类注解、springboot测试类、lombok的使用

    前提准备: 搭建一个springboot项目,详情请参见其它博客:点击前往 1 引入相关依赖 web.mysql.jpa.lombok <?xml version="1.0" ...

  4. ABP 教程文档 1-1 手把手引进门之 AngularJs, ASP.NET MVC, Web API 和 EntityFramework(官方教程翻译版 版本3.2.5)含学习资料

    本文是ABP官方文档翻译版,翻译基于 3.2.5 版本 转载请注明出处:http://www.cnblogs.com/yabu007/  谢谢 官方文档分四部分 一. 教程文档 二.ABP 框架 三. ...

  5. golang sql database drivers

    https://github.com/golang/go/wiki/SQLDrivers SQL database drivers The database/sql and database/sql/ ...

  6. [LeetCode] 链表反转相关题目

    暂时接触到LeetCode上与链表反转相关的题目一共有3道,在这篇博文里面总结一下.首先要讲一下我一开始思考的误区:链表的反转,不是改变节点的位置,而是改变每一个节点next指针的指向. 下面直接看看 ...

  7. Tomcat安装和目录简介

    要知道动态的网页必须要有服务器的支撑! 1.知名的java web服务器 Tomcat:Apache组织发布,免费开源的,轻量级 JBoss.WebLogic是商用的,价格较高,但相对于开源的更加稳定 ...

  8. SQL基础学习_04_视图

    视图 1. 视图的创建     视图就是保存好的SELECT语句,这些SELECT语句执行之后会产生新的表,所以在SQL中,视图和表是不做差别对待的,也就是SQL也可以对视图做一些操作:     由于 ...

  9. Python学习_08_函数式编程

    在python中,函数名也是一个变量,代表对一个函数内容的引用,意味着可以作为参数传入到其他函数中,根据这个特性,发散出装饰器.闭包等概念,并涉及到变量作用域等问题. 函数 python中函数操作符为 ...

  10. 适合小白/外行的git与github最基础最浅显教程

    首先声明,这是适合小白/外行/初学者/学生看的最基础最简单的git与github教程,已经能使用svn,git等工具的朋友请不要看这篇文章来浪费时间了. 想进一步学习git的,推荐去廖雪峰博客学习. ...