Dungeon Master poj 2251 dfs
Language:
Default
Dungeon Master
Description
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? Input
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. Output
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
where x is replaced by the shortest time it takes to escape.
Sample Input 3 4 5 Sample Output Escaped in 11 minute(s). Source |
题意:给你一个三维迷宫。从起点到终点求最短步数。
思路:和二维的迷宫问题差点儿相同,略微改成三维的即可了。
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <queue>
using namespace std; struct Node
{
int x,y,z;
int step;
}; char mp[35][35][35];
int visit[35][35][35];
int dir[6][3]={-1,0,0,1,0,0,0,-1,0,0,1,0,0,0,1,0,0,-1};//x,y,z
int N,M,P,sx,sy,sz,ex,ey,ez; bool ISok(int x,int y,int z)
{
if (z>=0&&z<P&&x>=0&&x<N&&y>=0&&y<M&&mp[z][x][y]!='#'&&!visit[z][x][y])
return true;
return false;
} void bfs()
{
Node st,now;
memset(visit,0,sizeof(visit));
queue<Node>Q;
visit[sz][sx][sy]=1;
st.x=sx;st.y=sy;st.z=sz;
st.step=0;
Q.push(st);
while (!Q.empty())
{
st=Q.front();
Q.pop();
if (st.x==ex&&st.y==ey&&st.z==ez)
{
printf("Escaped in %d minute(s).\n",st.step);
return ;
}
for (int i=0;i<6;i++)
{
now.x=st.x+dir[i][0];
now.y=st.y+dir[i][1];
now.z=st.z+dir[i][2];
if (ISok(now.x,now.y,now.z))
{
now.step=st.step+1;
visit[now.z][now.x][now.y]=1;
Q.push(now);
}
}
}
printf("Trapped!\n");
return ;
} int main()
{
while (scanf("%d%d%d",&P,&N,&M)&&P)
{
for (int i=0;i<P;i++)
{
for (int j=0;j<N;j++)
{
scanf("%s",mp[i][j]);//z,x,y
for (int t=0;t<M;t++)
{
if (mp[i][j][t]=='S')
{
sx=j;sy=t;sz=i;
}
if (mp[i][j][t]=='E')
{
ex=j;ey=t;ez=i;
}
}
}
}
bfs();
}
return 0;
}
版权声明:本文博主原创文章,博客,未经同意不得转载。
Dungeon Master poj 2251 dfs的更多相关文章
- Dungeon Master POJ - 2251 (搜索)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 48605 Accepted: 18339 ...
- (广搜)Dungeon Master -- poj -- 2251
链接: http://poj.org/problem?id=2251 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2137 ...
- Dungeon Master POJ - 2251(bfs)
对于3维的,可以用结构体来储存,详细见下列代码. 样例可以过,不过能不能ac还不知道,疑似poj炸了, #include<iostream> #include<cstdio> ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- B - Dungeon Master POJ - 2251
//纯bfs #include <iostream> #include <algorithm> #include <cstring> #include <cs ...
- kuangbin专题 专题一 简单搜索 Dungeon Master POJ - 2251
题目链接:https://vjudge.net/problem/POJ-2251 题意:简单的三维地图 思路:直接上代码... #include <iostream> #include & ...
- 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(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
随机推荐
- Android学习路径(十)怎么会Action Bar堆放在布局
默认情况下.action bar出如今activity窗体的顶部.稍微降低了activity布局的总空间. 假设你想隐藏或者显示action bar.在这堂用户体验的课程中,你能够通过调用hide() ...
- Android应用程序绑定服务(bindService)的过程源码分析
Android应用程序组件Service与Activity一样,既能够在新的进程中启动,也能够在应用程序进程内部启动:前面我们已经分析了在新的进程中启动Service的过程,本文将要介绍在应用程序内部 ...
- IDF - CTF - 牛刀小试
找学校CTF好地方,IDF实验室CTF训练营(http://ctf.idf.cn/). . 刚接触CTF.来玩下牛刀小试.AK了. . 好爽好爽.. 1.摩斯password 嘀嗒嘀嗒嘀嗒嘀嗒 时针它 ...
- FastReport的再次使用
FastReport.Net是一款功能齐全的报表分析解决方案. 前两年工作的时候就是使用FastReport进行报表设计,只是当时使用的时候都是调用别人写好的帮助类,直接调用即可.当时让人觉得不明觉厉 ...
- AspNet MVC4 教育-28:Asp.Net MVC4 Ajax技术部门四舍五入余速Demo
A.创建一个Basic项目类型. B.于Models创建一个文件夹: DivModel.cs: using System; using System.Collections.Generic; usin ...
- Spark大师之路:广播变量(Broadcast)源代码分析
概述 近期工作上忙死了--广播变量这一块事实上早就看过了,一直没有贴出来. 本文基于Spark 1.0源代码分析,主要探讨广播变量的初始化.创建.读取以及清除. 类关系 BroadcastManage ...
- Docker简介(转)
Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何 ...
- Android:创建耐磨应用 - 定义自己的布局
创建自己的自定义布局(Creating Custom Layouts) 本文介绍如何创建自己的自定义通知和使用可穿戴UI库来创建自己的自定义布局同时你还需要知道耐磨设计标准(Wear Design P ...
- axure7.0下载安装教程
做产品必需要有原型设计.我们公司称为做demo. demo你能够用ppt做,或者直接做图片.这样给甲方基本通只是. 也能够直接用html做,这样非常慢.尽管真正研发时或许能够复用: 平衡的方案,也是最 ...
- VS2008让自己掌控的定义编译项目后,自己主动添加到工具箱
在VS2008中,假设在项目里写了一个用户控件.编译后这个控件是不会自己主动出现到工具箱的.按例如以下设置就能够解决问题 工具=>选项=>Windows窗口设计器=>常规=>A ...