3D dungeon

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描写叙述
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 <stdio.h>
#include <string.h>
#include <queue>
using std::queue;
char map[32][32][32], vis[32][32][32];
int a, b, c, X, Y, Z;
const int mov[][3] = {0, 0, 1, 0, 0, -1, 0, 1,
0, 0, -1, 0, 1, 0, 0, -1, 0, 0};
struct Node{
int x, y, z, steps;
};
queue<Node> Q; bool check(Node t){
if(t.x < 0 || t.y < 0 || t.z < 0) return 0;
if(t.x >= a || t.y >= b || t.z >= c) return 0;
if(vis[t.x][t.y][t.z] || map[t.x][t.y][t.z] == '#') return 0;
return 1;
} void BFS(){
while(!Q.empty()) Q.pop(); Node t, n = {0};
n.x = X; n.y = Y; n.z = Z;
vis[X][Y][Z] = 1;
Q.push(n); while(!Q.empty()){
n = Q.front(); Q.pop(); for(int i = 0; i < 6; ++i){
t = n; ++t.steps;
t.x += mov[i][0];
t.y += mov[i][1];
t.z += mov[i][2]; if(check(t)){
if(map[t.x][t.y][t.z] == 'E'){
printf("Escaped in %d minute(s).\n", t.steps);
return;
}
vis[t.x][t.y][t.z] = 1;
Q.push(t);
}
}
}
printf("Trapped!\n");
} int main(){
while(scanf("%d%d%d", &a, &b, &c), a || b || c){ memset(vis, 0, sizeof(vis)); for(int i = 0; i < a; ++i){
for(int j = 0; j < b; ++j){
scanf("%s", map[i][j]);
for(int k = 0; k < c; ++k)
if(map[i][j][k] == 'S'){
X = i; Y = j; Z = k;
}
}
}
BFS();
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

NYOJ353 3D dungeon 【BFS】的更多相关文章

  1. NYOJ 353 3D dungeon 【bfs】

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

  2. 【bfs】抓住那头牛

    [题目] 农夫知道一头牛的位置,想要抓住它.农夫和牛都位于数轴上,农夫起始位于点N(0≤N≤100000),牛位于点K(0≤K≤100000).农夫有两种移动方式: 1.从X移动到X-1或X+1,每次 ...

  3. 【bfs】拯救少林神棍(poj1011)

    Description 乔治拿来一组等长的木棒,将它们随机地砍断,使得每一节木棍的长度都不超过50个长度单位.然后他又想把这些木棍恢复到为裁截前的状态,但忘记了初始时有多少木棒以及木棒的初始长度.请你 ...

  4. 【bfs】Knight Moves

    [题目描述] 输入nn代表有个n×nn×n的棋盘,输入开始位置的坐标和结束位置的坐标,问一个骑士朝棋盘的八个方向走马字步,从开始坐标到结束坐标可以经过多少步. [输入] 首先输入一个nn,表示测试样例 ...

  5. 【bfs】1252 走迷宫

    [题目描述] 一个迷宫由R行C列格子组成,有的格子里有障碍物,不能走:有的格子是空地,可以走. 给定一个迷宫,求从左上角走到右下角最少需要走多少步(数据保证一定能走到).只能在水平方向或垂直方向走,不 ...

  6. 【bfs】献给阿尔吉侬的花束

    [题目描述] 阿尔吉侬是一只聪明又慵懒的小白鼠,它最擅长的就是走各种各样的迷宫.今天它要挑战一个非常大的迷宫,研究员们为了鼓励阿尔吉侬尽快到达终点,就在终点放了一块阿尔吉侬最喜欢的奶酪.现在研究员们想 ...

  7. 【bfs】迷宫问题

    [题目描述] 定义一个二维数组: int maze[5][5] = { 0,1,0,0,0, 0,1,0,1,0, 0,0,0,0,0, 0,1,1,1,0, 0,0,0,1,0, }; 它表示一个迷 ...

  8. 【bfs】仙岛求药

    [题目描述] 少年李逍遥的婶婶病了,王小虎介绍他去一趟仙灵岛,向仙女姐姐要仙丹救婶婶.叛逆但孝顺的李逍遥闯进了仙灵岛,克服了千险万难来到岛的中心,发现仙药摆在了迷阵的深处.迷阵由M×N个方格组成,有的 ...

  9. 【bfs】BZOJ1102- [POI2007]山峰和山谷Grz

    最后刷个水,睡觉去.Bless All! [题目大意] 给定一个地图,为FGD想要旅行的区域,地图被分为n*n的网格,每个格子(i,j) 的高度w(i,j)是给定的.若两个格子有公共顶点,那么他们就是 ...

随机推荐

  1. 央视公然诽谤Linux操作系统,谁报告?

    考虑下面的观点: 这是今年5月111日上午11点04分央视播出的一则新闻,题为"工信部希望用户使用国产操作系统(替代XP). 该新闻报道,概念混乱,违背事实,误导公众,谁来举报?现举一例加以 ...

  2. Word001

    C# Word 类库 2009-08-06 22:10 13470人阅读 评论(10) 收藏 举报 c#objectstring文档microsoftexcel using System;using ...

  3. C++程序代写实现HashSet class

    C++程序代写实现HashSet class 专业程序代写(QQ:928900200) Implement a HashSet class for elements of type string.It ...

  4. ASP.NET执行循序

    首先第一次运行一个应用程序(WebSite或者WebApplication都是Web应用程序)第一次请求 -> 1,IIS -> 2,aspnet_isapi(非托管dll) -> ...

  5. gif动图快速制作方法(附工具)(转)

    现在写博客或是wiki的过程中,会经常引用到图片,特别是客户端经常与页面相关所以截图不可避.但是越来越多的效果仅仅一张图片是无法清楚的描述.并且博客或是wiki也是支持gif图的.gif图的制作方法有 ...

  6. 左右Map

    Person p=new Person("黄雄"); Map map=new HashMap(); map.put("p", p); p.setName(&qu ...

  7. BZOJ 2007 NOI2010 海拔高度 最小减产计划

    标题效果:YT城市是一个精心规划的城市.这个城市是东西向和南北向干道成n×n地区性.简单.可以YT作为一个城市广场,每个区域也可被视为一个正方形.因此,.YT市中含有(n+1)×(n+1)交叉口和2n ...

  8. OWIN编写中间件

    OWIN系列之自己动手编写中间件 一.前言 1.基于OWIN的项目摆脱System.Web束缚脱颖而出,轻量级+跨平台,使得ASP.NET应用程序只需依赖这个抽象接口,不用关心所运行的Web服务器. ...

  9. .net Quartz 服务 作业调度

    .net项目中使用Quartz   (1)在web.config中进行相关配置 <configSections> <section name="quartz" t ...

  10. Linux Kernel(Android) 加密算法汇总(三)-应用程序调用内核加密算法接口

    于Linux Kernel(Android) 加密算法总结(cipher.compress.digest)文章中.介绍了怎样在内核中增加三种不同类型的内核加密算法, 并给出了在内核模块中怎样调用他们的 ...