time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u

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! queue用法

queue 模板类的定义在<queue>头文件中。
queue 模板类需要两个模板参数,一个是元素类型,一个容器类
型,元素类型是必要的,容器类型是可选的,默认为deque 类型。
定义queue 对象的示例代码如下:
queue<int> q1;
queue<double> q2;

queue 的基本操作有:
入队,如例:q.push(x); 将x 接到队列的末端。
出队,如例:q.pop(); 弹出队列的第一个元素,注意,并不会返回被弹出元素的值。
访问队首元素,如例:q.front(),即最早被压入队列的元素。
访问队尾元素,如例:q.back(),即最后被压入队列的元素。
判断队列空,如例:q.empty(),当队列空时,返回true。
访问队列中的元素个数,如例:q.size()

 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; int main()
{
queue<int> q;
q.push();
q.push();
q.push();
printf("%d\n",q.size());
while(!q.empty())
{
int a=q.front();
q.pop();
printf("%d ",a);
}
printf("\n");
return ;
}

my daima

 #include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; const int INF=;
int l,r,c,sl,sr,sc,el,er,ec,d[][][];
char maps[][][]; struct Node
{
int l;
int r;
int c;
}; queue<Node> q; int dr[]={,,,-,,},dc[]={,,,,,-},dl[]={,-,,,,}; int bfs()
{
int i,j,k;
for(k=;k<=l;k++)
for(i=;i<=r;i++)
for(j=;j<=c;j++)
d[k][i][j]=INF;
Node s;
s.l=sl,s.r=sr,s.c=sc;
q.push(s);
d[sl][sr][sc]=; while(q.size())
{
Node now=q.front();
q.pop();
Node nex; if(now.l==el && now.r==er && now.c==ec)
break; for(i=;i<;i++)
{
nex.l=now.l+dl[i],nex.r=now.r+dr[i],nex.c=now.c+dc[i]; if(<=nex.l && nex.l<=l && <=nex.r && nex.r<=r && <=nex.c && nex.c<=c && maps[nex.l][nex.r][nex.c]!='#' && d[nex.l][nex.r][nex.c]==INF)
{
q.push(nex);
d[nex.l][nex.r][nex.c]=d[now.l][now.r][now.c]+;
}
}
}
return d[el][er][ec];
} int main()
{
int i,j,k;
while(scanf("%d %d %d",&l,&r,&c)!=EOF)
{
getchar();
if(l== && r== && c==)
break;
for(k=;k<=l;k++)
{
for(i=;i<=r;i++)
{
for(j=;j<=c;j++)
{
scanf("%c",&maps[k][i][j]);
if(maps[k][i][j]=='S')
sl=k,sr=i,sc=j;
if(maps[k][i][j]=='E')
el=k,er=i,ec=j;
}
getchar();
}
getchar();
} int ans=bfs();
if(ans==INF)
printf("Trapped!\n");
else
printf("Escaped in %d minute(s).\n",ans); /*printf("%d %d %d\n%d %d %d\n",sl,sr,sc,el,er,ec);
for(k=1;k<=l;k++)
{
for(i=1;i<=r;i++)
{
for(j=1;j<=c;j++)
{
printf("%7d ",d[k][i][j]);
}
printf("\n");
}
printf("\n");
}*/ }
return ;
}

dsdm

#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <queue> using namespace std; int l, r, c, res;
int sx, sy, sz, ex, ey, ez;
string m[][];
bool vis[][][], esp; struct Node {int x, y, z, rs;};
int dir[][] = {-,,,,,,,-,,,,,,,-,,,};
queue<Node> q; void bfs() {
Node s;
s.x = sx, s.y = sy, s.z = sz, s.rs = ;
while(!q.empty()) q.pop();
q.push(s);
while(!q.empty()) {
Node now = q.front(); q.pop();
Node tmp;
for (int i = ; i < ; ++i) {
int x = now.x+dir[i][];
int y = now.y+dir[i][];
int z = now.z+dir[i][];
if (x >= l || x < || y >= r || y < || z >= c || z < ) continue;
if (vis[z][x][y]) continue;
if (m[z][x][y] =='#') continue;
vis[z][x][y] = true;
tmp.x = x;
tmp.y = y;
tmp.z = z;
tmp.rs = now.rs +;
q.push(tmp);
if (x == ex && y == ey && z == ez) {
esp = true;
res = tmp.rs;
return ;
}
}
}
return ;
} int main() {
while(cin >> c >> l >> r) {
if (!l && !r && !c) break;
for (int i = ; i < c; ++i) {
for (int j = ; j < l; ++j) {
cin >> m[i][j];
for (int k = ; k < m[i][j].size(); ++k) {
if (m[i][j][k] == 'S') {
sx = j;
sy = k;
sz = i;
}
else if (m[i][j][k] == 'E') {
ex = j;
ey = k;
ez = i;
}
}
}
}
memset(vis, , sizeof(vis));
vis[sz][sx][sy] = true;
esp = false;
bfs();
if (esp) cout << "Escaped in "<<res<< " minute(s)." << endl;
else cout << "Trapped!" << endl;
}
return ;
}

Dungeon Master bfs的更多相关文章

  1. hdu 2251 Dungeon Master bfs

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

  2. POJ2251 Dungeon Master —— BFS

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

  3. 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 ...

  4. [poj] Dungeon Master bfs

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

  5. poj 2251 Dungeon Master( bfs )

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

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

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

  7. POJ2251 Dungeon Master(bfs)

    题目链接. 题目大意: 三维迷宫,搜索从s到e的最小步骤数. 分析: #include <iostream> #include <cstdio> #include <cs ...

  8. POJ 2251 Dungeon Master bfs 难度:0

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

  9. E - Dungeon Master BFS

    [NWUACM] 你被困在一个三维的空间中,现在要寻找最短路径逃生!空间由立方体单位构成你每次向上下前后左右移动一个单位需要一分钟你不能对角线移动并且四周封闭是否存在逃出生天的可能性?如果存在,则需要 ...

随机推荐

  1. zw版【转发·台湾nvp系列Delphi例程】HALCON OverpaintRegion1

    zw版[转发·台湾nvp系列Delphi例程]HALCON OverpaintRegion1 unit Unit1;interfaceuses Windows, Messages, SysUtils, ...

  2. yii2的redis扩展使用

    yii2支持了redis扩展,不需要在本地下载php的扩展库就可以很好的使用 1.下载windows的redis安装包打开cmd,进入安装包目录,使用redis-server.exe redis.co ...

  3. Elasticsearch--Date math在索引中的使用

    在Elasticsearch,有时要通过索引日期来筛选某段时间的数据,这时就要用到ES提供的日期数学表达式 描述: 特别在日志数据中,只是查询一段时间内的日志数据,这时就可以使用日期数学表达式,这样可 ...

  4. 5 Best Automation Tools for Testing Android Applications

    Posted In | Automation Testing, Mobile Testing, Software Testing Tools   Nowadays automated tests ar ...

  5. Qt可执行程序写入版本信息

    [1]新建Qt工程 1.1 具体新建步骤不赘述. 1.2 新建工程后文件目录如下: 1.3 留意对比一下你的代码目录,可以发现我的文件目录中多了一个rc类型的资源文件.那么,它也就是关键点. 1.4 ...

  6. PHP 加密的几种方式

    在使用PHP开发Web应用的中,很多的应用都会要求用户注册,而注册的时候就需要我们对用户的信息进行处理了,最常见的莫过于就是邮箱和密码了,本文意在讨论对密码的处理:也就是对密码的加密处理. MD5 相 ...

  7. flexbox in IE (10+ and 9 and 8)

    .parent { display: -webkit-box !important; display: -moz-box !important; display: -ms-flexbox !impor ...

  8. Pascal's Triangle

    class Solution { public: vector<vector<int>> generate(int numRows) { vector<vector< ...

  9. Hibernate API申明事务边界

    在Hibernate API中,Session和Transaction接口提供了以下声明事务边界的方法: 声明事务的开始边界: Transaction tx = session.beginTransa ...

  10. pg_dump 备份与恢复的简单操作

    pg_dump 是一个用于备份PostgreSQL数据库的工具.    该工具生成的转储格式可以分为两种,    脚本  :     其中脚本格式是包含许多SQL命令的纯文本格式  (常用)    归 ...