POJ P2251 Dungeon Master 题解
深搜,只不过是三维的。
#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 题解的更多相关文章
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- 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 ...
- POJ.2251 Dungeon Master (三维BFS)
POJ.2251 Dungeon Master (三维BFS) 题意分析 你被困在一个3D地牢中且继续寻找最短路径逃生.地牢由立方体单位构成,立方体中不定会充满岩石.向上下前后左右移动一个单位需要一分 ...
- BFS POJ 2251 Dungeon Master
题目传送门 /* BFS:这题很有意思,像是地下城,图是立体的,可以从上张图到下一张图的对应位置,那么也就是三维搜索,多了z坐标轴 */ #include <cstdio> #includ ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
随机推荐
- 【rt-thread】1、快速建立rt-thread nano最小裁剪工程
快速建立rt-thread nano最小裁剪工程 使用keil5建立 1.下载rt-thread 3.03版本,3.03程序占用最小 2.使用 CubeMX 配置工程 3.选择添加rt-thread ...
- 【VUE】1.搭建一个webpack项目
1.npm之类的安装跳过 2.安装npm install -g @vue/cli-init 初始化项目目录 vue init webpack vue_cutter_point_blog_admin 并 ...
- SQL SERVER 查询所有表大小
DECLARE @T TABLE ( [name] VARCHAR(max), [rows] INT, reserved VARCHAR(max), data_size VARCHAR(max), i ...
- 代理服务器支持https(转)
原标题:让代理服务器支持HTTPS很难吗? http://www.site-digger.com/html/articles/20151203/107.html
- 通过分析 WPF 的渲染脏区优化渲染性能
原文:通过分析 WPF 的渲染脏区优化渲染性能 本文介绍通过发现渲染脏区来提高渲染性能. 本文内容 脏区 Dirty Region WPF 性能套件 脏区监视 优化脏区重绘 脏区 Dirty Regi ...
- python中ocr软件tesseract使用
首先要看原版的参考 https://github.com/madmaze/pytesseract 直接上代码, import pytesseractfrom PIL import Image imag ...
- Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现
Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现 一丶进程基础知识 什么是程序: 程序就是一堆文件 什么是进程: 进程就是一个正在 ...
- 【开发工具】-Idea代码提示忽略大小写
设置路径:File–>Settings–>Editor–>General–>Code Completion–>Match case 取消Match case 勾选. [o ...
- 笔谈 cocoapods的安装与使用
因为要重构播放器库,所以就需要参考网上的开源项目,在播放器开源项目这块,kxmovie开源项目是值得参考的一个项目.在github下载下来后,运行该工程,发现其用到了cocoapods来管理第三方库, ...
- ffmpeg基础使用
https://www.jianshu.com/p/ddafe46827b7