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 ...
随机推荐
- 一个基于tcp的socket简单对话小例子
首先我们需要写连个py文件,一个server,一个client. import socket sk = socket.socket() # sk.bind(('ip',port)) sk.bind(( ...
- KepServerEX读写三菱PLC,车间现场测试记录,带你了解【数据采集的困境】的前世与今生
1.不了解KepServerEX 的鞋童,可以先了解一下OPC UA,OPC UA服务端.我们当前项目读写三菱PLC是自己写的类库,但我感觉调用不够方便灵活,工作之余用OPC UA方式尝试一下 2.数 ...
- SVN客户端教程
.SVN是一个自由/开源的版本控制系统,一组文件存放在中心版本库,记录每一次文件和目录的修改,Subversion允许把数据恢复到早期版本,或是检查数据修改的历史,Subversion可以通过网络访问 ...
- 使用jconsole分析内存情况
http://www.cnblogs.com/dava/p/6686436.html
- JavaScript之DOM节点操作
a.appendChild(b) 追加标签 a是b的父级,将b追加到a中 追加标签 a.insertBefore(b,c); a是b和c的父级,在c前面插入b 删除标签 a.removeCli ...
- kthread_run
头文件 include/linux/kthread.h 创建并启动 /** * kthread_run - create and wake a thread. * @threadfn: the fun ...
- Android 为TV端助力之解决ViewPager嵌套RecyclerView水平滑动问题
public class MyViewPager extends ViewPager { private RecyclerView recyclerView; public MyViewPager(@ ...
- mybatis批量更新报错 org.mybatis.spring.MyBatisSystemException
具体报错信息: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Bin ...
- Linux环境变量设置declare/typeset
形而上,质在内!形形色色,追寻本质! declare/typeset declare 或 typeset 是一样的功能,就是在宣告变数的属性 declare 后面并没有接任何参数,那么bash 就会主 ...
- jenkins使用邮件功能
jenkins发送邮件 在日常构建后,需要及时将构建结果发送给相应的人员.这时就可以使用jenkins自带的邮件配置系统. 1 开通邮箱的SMTP服务,需要发送短信验证开启 2 进入"系统管 ...