算法:广搜;

描述 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?

输入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.输出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!样例输入3 4 5

S....

.###.

.##..

###.#



#####

#####

##.##

##...



#####

#####

#.###

####E



1 3 3

S##

#E#

###



0 0 0

样例输出

Escaped in 11 minute(s).

Trapped!

代码:

 #include <iostream>
#include <cstring>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
using namespace std;
char ch[35][35][35];
int n,m,k,x1,x2,y1,y2,z1,z2;
int a[6][3]={1,0,0,-1,0,0,0,1,0,0,-1,0,0,0,1,0,0,-1};
struct dot
{
int x,y,z,step;
} ;
int cmp(int ax,int ay,int az)
{
if(ax>=0&&ax<n&&ay>=0&&ay<m&&az>=0&&az<k&&ch[ax][ay][az]=='.') return 1;
return 0;
}
int bfs()
{
queue<dot>que;
dot cur,loer;
cur.x=x1;cur.y=y1;cur.z=z1;
cur.step=0;
ch[x1][y1][z1]='#';
que.push(cur);
while(que.size())
{
loer=que.front();
que.pop();
if(loer.x==x2&&loer.y==y2&&loer.z==z2)
return loer.step;
for(int i=0;i<6;i++)
{
cur=loer;
cur.x+=a[i][0];
cur.y+=a[i][1];
cur.z+=a[i][2];
if(cmp(cur.x,cur.y,cur.z))
{
ch[cur.x][cur.y][cur.z]='#';
cur.step++;
que.push(cur);
}
}
}
return -1;
}
int main()
{
int i,j,p;
while(cin>>n>>m>>k&&n&&m&&k)
{
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
for(p=0;p<k;p++)
{
cin>>ch[i][j][p];
if(ch[i][j][p]=='S')
{x1=i;y1=j;z1=p;}
if(ch[i][j][p]=='E')
{x2=i;y2=j;z2=p;ch[i][j][p]='.';}
}
}
}
int ans=bfs();
if(ans>=0) cout<<"Escaped in "<<ans<<" minute(s)."<<endl;
else cout<<"Trapped!"<<endl;
}
return 0;
}

3D dungeon的更多相关文章

  1. nyoj 353 3D dungeon

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 You are trapped in a 3D dungeon and need to find ...

  2. NYOJ353 3D dungeon 【BFS】

    3D dungeon 时间限制:1000 ms  |  内存限制:65535 KB 难度:2 描写叙述 You are trapped in a 3D dungeon and need to find ...

  3. NYOJ--353--bfs+优先队列--3D dungeon

    /* Name: NYOJ--3533D dungeon Author: shen_渊 Date: 15/04/17 15:10 Description: bfs()+优先队列,队列也能做,需要开一个 ...

  4. NYOJ 353 3D dungeon 【bfs】

    题意:给你一个高L长R宽C的图形.每个坐标都能够视为一个方格.你一次能够向上.下.左,右,前,后任一方向移动一个方格, 可是不能向有#标记的方格移动. 问:从S出发能不能到达E,假设能请输出最少的移动 ...

  5. POJ 2251 Dungeon Master(3D迷宫 bfs)

    传送门 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 28416   Accepted: 11 ...

  6. poj 2251 Dungeon Master

    http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  7. Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏

    Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...

  8. Dungeon Master bfs

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

  9. 暑假集训(1)第三弹 -----Dungeon Master(Poj2251)

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

随机推荐

  1. codevs 4768 跳石头

    传送门 表示去年不会,二分是啥都不知道,一脸懵逼. 今年再做,虽然知道二分是啥了,但依旧不会,蒙蔽了好几天,最后还是看了题解. #include<cstdio> #define M 510 ...

  2. 针对上一篇文章中的代码,想出的重构方案(python实现)

    #!/usr/bin/env python class Processor: def __init__(self, processor): self.processor = processor def ...

  3. android防止系统截屏

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow() ...

  4. LeetCode_ 4 sum

    Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = tar ...

  5. 程序自动生成Dump文件()

    前言:通过drwtsn32.NTSD.CDB等调试工具生成Dump文件, drwtsn32存在的缺点虽然NTSD.CDB可以完全解决,但并不是所有的操作系统中都安装了NTSD.CDB等调试工具.了解了 ...

  6. 【HDOJ】1547 Bubble Shooter

    两次BFS,一次扫描关联点.一次扫描可能掉落的情况(即再次扫描所有非爆炸的联通点).余下未被扫描的点均爆炸. #include <cstdio> #include <cstring& ...

  7. NOIP

    最近把历年题刷一下吧... 发现0几年的题不是爆搜就是高精度,恶心死了...直接跳过,做些有意思的... P1129产生数 floyed之后乘法原理统计   P1810导弹拦截 贪心,按距某个点的距离 ...

  8. REST服务中的日志可视化(关键技术实现)

    引言 在系统构建完成之后,我们通常会使用REST API对外提供服务,在REST API的处理过程中经常会出现一些异想不到的问题(用户权限不足.参数不全.数据库访问异常等),导致请求失败,很多时候用户 ...

  9. 《Ruby语言入门教程v1.0》学习笔记-02

    9.18 第四章 一切都是对象 这个章节的例子都举得很浅显易懂,而且作者的语言= =噗,委实生动有趣啊是~~ 4.1  两种思维方式 初期的编程思想是:以“如何做”为指导来编写代码.这时期的编程语言叫 ...

  10. POJ 1700 坐船过河问题

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82974#problem/E 解题思路:当n>=4,假设n个人单独过河所需 ...