深搜,只不过是三维的。

 #include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;
int l,r,c;
int sx,sy,sz;
int ex,ey,ez;
int ans=;
char map[][][];
int book[][][]= {};
int flag=;
void dfs(int x,int y,int z,int step) {
if(x==ex&&y==ey&&z==ez) {
ans=min(ans,step);
flag=;
return;
}
if(map[x+][y][z]!='#'&&book[x+][y][z]!=&&x+<=l) {
book[x+][y][z]=;
dfs(x+,y,z,step+);
book[x+][y][z]=;
}
if(map[x-][y][z]!='#'&&book[x-][y][z]!=&&x->=) {
book[x-][y][z]=;
dfs(x-,y,z,step+);
book[x-][y][z]=;
}
if(map[x][y+][z]!='#'&&book[x][y+][z]!=&&y+<=r) {
book[x][y+][z]=;
dfs(x,y+,z,step+);
book[x][y+][z]=;
}
if(map[x][y-][z]!='#'&&book[x][y-][z]!=&&y->=) {
book[x][y-][z]=;
dfs(x,y-,z,step+);
book[x][y-][z]=;
}
if(map[x][y][z+]!='#'&&book[x][y][z+]!=&&z+<=c) {
book[x][y][z+]=;
dfs(x,y,z+,step+);
book[x][y][z+]=;
}
if(map[x][y][z-]!='#'&&book[x][y][z-]!=&&z->=) {
book[x][y][z-]=;
dfs(x,y,z-,step+);
book[x][y][z-]=;
}
}
int main() {
while((cin>>l>>r>>c)&&l!=&&r!=&&c!=) {
for(int i=; i<=l; i++) {
for(int j=; j<=r; j++) {
for(int k=; k<=c; k++) {
cin>>map[i][j][k];
if(map[i][j][k]=='S') {
sx=i;
sy=j;
sz=k;
book[i][j][k]=;
}
if(map[i][j][k]=='E') {
ex=i;
ey=j;
ez=k;
}
}
}
}
dfs(sx,sy,sz,);
if(flag==) {
cout<<"Trapped!"<<endl;
}
else
{
cout<<"Escaped in "<<ans<<" minute(s)."<<endl;
}
memset(book,,sizeof(book));
flag=;
ans=;
}
}
请各位大佬斧正(反正我不认识斧正是什么意思)

POJ P2251 Dungeon Master 题解的更多相关文章

  1. POJ 2251 Dungeon Master(地牢大师)

    p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...

  2. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  3. POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索)

    POJ 2251 Dungeon Master /UVA 532 Dungeon Master / ZOJ 1940 Dungeon Master(广度优先搜索) Description You ar ...

  4. POJ.2251 Dungeon Master (三维BFS)

    POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...

  5. BFS POJ 2251 Dungeon Master

    题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...

  6. poj 2251 Dungeon Master

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

  7. POJ 2251 Dungeon Master (三维BFS)

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

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

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

  9. POJ 2251 Dungeon Master (非三维bfs)

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 55224   Accepted: 20493 ...

随机推荐

  1. 【Python爬虫案例学习】下载某图片网站的所有图集

    前言 其实很简短就是利用爬虫的第三方库Requests与BeautifulSoup. 其实就几行代码,但希望没有开发基础的人也能一下子看明白,所以大神请绕行. 基本环境配置 python 版本:2.7 ...

  2. 安装nginx1.16.1版本

    安装nginx1.16.1版本 一.添加源 到 cd /etc/yum.repos.d/ 目录下 新建nginx.repo 文件 vim nginx.repo 输入以下信息 [nginx-stable ...

  3. VM配置Centos(第十三步分区设置)

    1.点击开启此虚拟机之后,选择第一个 (注意:如果鼠标不显示出来,按alt+ctrl键) 2.然后选择skip跳过检测,如果选择了ok就会有很长时间的检测 3.然后选择NEXT 4.选择中文,然后点击 ...

  4. 个人学习笔记:C语言程序结构

    个人笔记:C语言程序 函数 语句 输入输出对象 标识符 关键字 函数 一个C语言源程序,是由一个或多个函数定义顺序组成的,其中必须有一个函数名为main的主函数.C语言源程序中的函数是指完成特定数据处 ...

  5. Zipkin存储Sleuth信息实现调用链追踪的几种方法

    版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/alva_xu/article/detail ...

  6. 引用和自包含令牌(Reference Tokens and Introspection)

    访问令牌可以有两种形式:自包含的和引用的. 自包含令牌(Self-contained tokens): 使用受保护的.有时间限制的数据结构,该结构包含元数据,并声明通过网络传递用户或客户机的身份.一种 ...

  7. Spring mvc请求处理流程详解(一)之视图解析

      本文链接:https://blog.csdn.net/lchpersonal521/article/details/53112728 前言 Spring mvc框架相信很多人都很熟悉了,关于这方面 ...

  8. Matlab装饰模式

    装饰器模式(Decorator Pattern)允许向一个现有的对象添加新的功能,同时又不改变其结构.根据https://www.runoob.com/design-pattern/decorator ...

  9. vim插件(vim-emmet)安装步骤

    vim安装插件  vim-emmetvim-emmet网址  https://www.vim.org/scripts/script.php?script_id=2981pathogen.vim网址  ...

  10. koa2---koa-bodyparser中间件

    对于POST请求的处理,koa-bodyparser中间件可以把koa2上下文的formData数据解析到ctx.request.body中 安装: npm install --save koa-bo ...