题目描述

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....
.###.
.##..
###.######
#####
##.##
##...#####
#####
#.###
####E1 3 3
S##
#E#
###0 0 0

样例输出

Escaped in 11 minute(s).
Trapped!

提示

本题的意思其实就是一个3D迷宫,相对与2d 迷宫就多了一个z,

思路bsf

dfs应该会超时;

#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
struct Node
{int x , y, z, step;Node() {} Node(int xx,int yy,int zz,int ss) : x(xx) , y (yy) , z(zz) , step(ss) {}
};
int sx,sy,sz,ex,ey,ez;
const int dx[6] = { 0,0,1,0,-1,0 };
const int dy[6] = { 0,0,0,1,0,-1 };
const int dz[6] = { -1,1,0,0,0,0 };
char a[35][35][35];
int book[35][35][35];
int n, m ,l ;
int bfs(int x,int y,int z,int step)
{queue<Node> Q;Q.push(Node(x,y,z,step));while(!Q.empty()){Node u = Q.front() ;Q.pop();if(u.x == ex && u.y == ey && u.z == ez){return u.step ;} int nowx,nowy,nowz,nows;for(int i = 0 ; i < 6 ; i++){nowx = u.x + dx[i] ;nowy = u.y + dy[i] ;nowz = u.z + dz[i] ;nows = u.step + 1 ;if(nowx>=0 && nowx < n && nowy >= 0 && nowy < m && nowz >= 0 && nowz < l&&a[nowx][nowy][nowz] != '#' &&book[nowx][nowy][nowz] == 0 ){book[nowx][nowy][nowz] = 1 ;//    a[nowx][nowy][nowz] = '#';Q.push(Node(nowx,nowy,nowz,nows)) ; }}}return -1 ;
}
int main()
{while(cin>>n>>m>>l){memset(a,0,sizeof(a));memset(book,0,sizeof(book));if(n==0 && m==0 && l == 0){break;}for(int i=0 ; i < n ; i++){for(int j=0 ; j < m ; j++){for(int k=0 ; k < l ; k++){cin>>a[i][j][k];if(a[i][j][k] == 'S'){sx=i;sy=j;sz=k;}if(a[i][j][k] == 'E'){ex=i;ey=j;ez=k;}/*if(a[i][j][k] == '#'){book[i][j][k] = 1;}*/}}}book[sx][sy][sz] = 1;int ans=bfs(sx,sy,sz,0);if(ans==-1){cout<<"Trapped!"<<endl;}else{printf("Escaped in %d minute(s).",ans);cout<<endl;}} }

3Ddungeon ~ 3D迷宫 BFS相关推荐

  1. 用webgl打造自己的3D迷宫游戏

    用webgl打造自己的3D迷宫游戏 2016/09/19 · JavaScript · WebGL 原文出处: AlloyTeam    背景:前段时间自己居然迷路了,有感而发就想到写一个可以让人迷路 ...

  2. qt 3d迷宫游戏_《加雷利亚的地下迷宫与魔女的旅团》最新情报公布

    日本一旗下最新作品<加雷利亚的地下迷宫与魔女的旅团(Coven and labyrinth of Galleria)>公布了有关本作角色和新登场Facet的最新情报,让我们一起来看看吧! ...

  3. Python 用Ursina引擎制作一个3D迷宫游戏

    Ursina是一个3D引擎,初步使用方法,见以下文章: 手把手教你用Python编一个<我的世界> 1. 认识Ursina并学会绘制立体图形_Leleprogrammer的博客-CSDN博 ...

  4. qt 3d迷宫游戏_玩游戏找不到路是如何成为常态的?游戏视角选择的得与失

    游戏刚开始兴起的时候,游戏视角还不是问题.由于画面技术的限制,早期的游戏无一例外都是2D平面画面.3D游戏兴起以后,设计者游戏视角的选择更加多样,在带来了更多样游戏体验的同时也劝退了大批游戏玩家.3D ...

  5. 3D迷宫(二)babylon.js

    3D迷宫(二)babylon.js 续上一篇的文章. 前面说到迷宫的算法,地图生成路线的代码如下: // 绘制 地图 数据this.__proto__.MapDrawData = function() ...

  6. 献给阿尔吉侬的花束(二刷,迷宫bfs,模板题)

    文章目录 Question Ideas Code Question 阿尔吉侬是一只聪明又慵懒的小白鼠,它最擅长的就是走各种各样的迷宫. 今天它要挑战一个非常大的迷宫,研究员们为了鼓励阿尔吉侬尽快到达终 ...

  7. 3D迷宫(一) babylon.js

    3D迷宫(一) babylon.js 这是我的第一个3D游戏,基于上次的迷宫小游戏制作的,之后学了babylon.js,就乘机做了个3D迷宫的,可以是边学边做的小游戏. 基本都是用到babylon.j ...

  8. qt 3d迷宫游戏_Switch游戏 | 吃豆旅行走走停停

    <吃豆人>这款游戏,阿狐相信很多鸡友都不陌生.它是一个非常简单的游戏,只需要一个十字键就可以玩,操作简单却成为了80年代最经典的街机游戏之一,<吃豆人>承载了不少人的记忆. 吃 ...

  9. 【动态规划】机器人走迷宫-BFS

    机器人走迷宫-BFS 题目描述:给一个矩阵,0代表可走位置,1代表障碍物 给定起点和终点和行走规则(上.下.左.右),输出最短路径 探寻最短路径-BFS 首先定义两个辅助函数,valid_action ...

最新文章

  1. C#操作NPOI插件的HSSFWorkBook,常见的那些坑
  2. linux 文件服务,Linux操作系统之文件服务(ftp、nfs)
  3. JDBC之二:DAO模式
  4. 初学 Delphi 嵌入汇编[10] - 函数返回值与寄存器
  5. android动画详解
  6. spring step 1 : 什么是spring
  7. springmvc 配置 tag lib_Java自学之springMVC:Hello Spring MVC
  8. 几何级数 函数 matlab,matlab 实验05数据的统计分析
  9. geteditor p 取消自动_自动挡汽车最热问题,N档到底是干什么用的?
  10. Spark源码分析之HashShuffle读写流程
  11. Android自定义UI实例
  12. Xampp mysql启动
  13. centos安装wget_宝塔是干什么的?3分钟教会你云服务器上安装宝塔面板
  14. ureport 显示html,UReport2 与业务结合
  15. BAAF-Net源码阅读
  16. 监听imput框的内容变化
  17. 笔记本一直提示计算机内存不足怎么办,笔记本电脑内存不足怎么解决
  18. gmtime() php,C语言gmtime()函数:把clock中的时间转换为格林尼治标准时间
  19. 云服务器多开账号,怎么用云服务器多开模拟器
  20. 分享一个超nice的数据分析实战案例, “手把手”教学,收藏等于学会

热门文章

  1. SpringBoot搭建在线聊天室
  2. 55/45 Jump Game 跳跃游戏
  3. 使用poi导入Excel文件兼容性问题,The supplied data appears to be in the OLE2 Format.
  4. windows配置PYTHONPATH环境变量的方法
  5. ue4 读取本地文件
  6. 数据库Mysql自增锁问题原来可以这么解决
  7. 动手学深度学习之目标检测基础
  8. Dubbo+Flutter在线交友平台教程第三天 今日佳人功能实现
  9. 10年前的顶级电脑性能仍然能赶上现在的主流电脑,是PC行业的骄傲还是PC行业的悲哀?
  10. 最新python毕业设计选题汇总