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. 夺命雷公狗---DEDECMS----22dedecms让A标签进入对应的内容页

    我们的模版里的超链接都是写死的,这都是不符合实际网站的需求的,我们要将他让他边活的,而并非死的.. 我们首先要将前端给我们的内容页面的模版放到目标目录里面,但是我们的内容页的模版名叫啥呢?我们可以来查 ...

  2. 夺命雷公狗---DEDECMS----17dedecms头条信息的取出

    我们在有些开发时候可能会用到些头条的文章,,添加过程如下所示: 我们在前台遍历数据的时候可以这样, 然后在后台更新首页模版后在去看下首页,效果如下所示:

  3. Power Gating的设计(模块二)

    针对lower power的验证,由cpf/upf来建模,包括: 1)power gating的功能模型(在power gate之后将output force为x) 2)isolation功能模型: ...

  4. PAT乙级 1024. 科学计数法 (20)

    1024. 科学计数法 (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 HOU, Qiming 科学计数法是科学家用来表示很 ...

  5. 关于VS 中 HttpHandler 的设置 500.23

    前一段时间在讲 HttpHandler 的过程中遇到一些问题,在此分享一下. 使用VS2012 添加HttpHandler后,在web.config配置的节点如下: <?xml version= ...

  6. 在Debian下安装ibus输入法

    sudo apt-get install ibus ibus-pinyin im-switch sudo apt-get install ibus-googlepinyin im-switch -s ...

  7. Javascript 类与静态类的实现-js面向对象

    在Javascript里,对面向对象并没有一个直接的实现,对于代码方面也是非常的灵活. 今天所要说的就是,如何在Javascript里写类与静态类,这是本人一惯用的方法,你也可以有更为方便的,也可以发 ...

  8. jQuery上传插件,文件上传测试用例

    jQuery上传插件,文件上传测试用例 jQuery File Upload-jQuery上传插件介绍http://www.jq22.com/jquery-info230 jQuery File Up ...

  9. Linux Kernel中断子系统来龙去脉浅析【转】

    转自:http://blog.csdn.net/u011461299/article/details/9772215 版权声明:本文为博主原创文章,未经博主允许不得转载. 一般来说,在一个device ...

  10. IIS7.5真变态,服务器时间格式导致不生成WebResource.axd

    把时间调成HH:mm格式后,IIS不生成WebResource.axd了,,,从凌晨一点弄到现在......