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. 【linux】暂时解决sis m672(神舟F4000 D9) linux驱动 宽屏分辨率的问题?

    1. 首先安装包 sudo apt-get install gcc make binutils git xorg-dev mesa-common-dev libdrm-dev libtool buil ...

  2. 【HDNOIP】HD201404最短路径

    HD201404最短路径 [试题描述] a.b.c是3个互不相等的1位正数,用它们和数字0可以填满一个n行n列的方格阵列,每格中都有4种数码中的一个.填入0的格子表示障碍物,不能属于任何路径.你是否能 ...

  3. 数据库性能优化:SQL索引

    SQL索引在数据库优化中占有一个非常大的比例, 一个好的索引的设计,可以让你的效率提高几十甚至几百倍,在这里将带你一步步揭开他的神秘面纱. 1.1 什么是索引? SQL索引有两种,聚集索引和非聚集索引 ...

  4. COM编程之二 接口

    [1]接口 DLL的接口是它所输出的那些函数. C++类的接口是该类的一个成员函数集. COM接口是包含一个函数指针数组的内存结构. 每一个数组元素包含的是一个由组件所实现的函数的地址. 在COM中接 ...

  5. Java、JVM和操作系统之间的关系,写给新人,

    来张图:这个帖子写给新人的,老玩家就直接无视他,因为这个完完全全是白话基础原理. 解释:上面的图是从上往下依次调用的关系. 操作系统(Windows/Linux)管理硬件,让硬件能够正常.合理的运行, ...

  6. Hibernate,JPA注解@SecondaryTable

    使用类一级的 @SecondaryTable或@SecondaryTables注解可以实现单个实体到多个表的映射. 使用 @Column或者 @JoinColumn注解中的table参数可指定某个列所 ...

  7. JavaEE基础(十一)/Eclipse介绍

    1.Java开发工具(常见开发工具介绍) A:操作系统自带的记事本软件 B:高级记事本软件 C:集成开发环境 IDE (Integrated Development Environment) D:Ec ...

  8. 以雅酷网为实例从技术上说说dedecms的seo优化要注意哪些?

    目前在做雅酷网 ,雅酷卡是雅酷时空公司的产品,我个人感觉用雅酷卡消费还是比较实惠的,而雅酷卡的特色便是雅酷健身卡,很多站长成天的趴电脑上,可以考虑办一张这样的卡,在周末的时候去健身中心活动活动,还是比 ...

  9. 关于childNodes的length的问题

    <ul id="ul1"> <li></li> <li></li> </ul> 这个时候如果 documen ...

  10. Cow Bowling

    Cow Bowling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15585 Accepted: 10363 Descrip ...