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: ...
随机推荐
- Cocos2d-x 单点触摸--让我们用手指动起来的精灵
转载请注明出处:http://blog.csdn.net/oyangyufu/article/details/25656673 效果图: CCTouch类装载了触摸点的信息.包含触摸点的横纵坐标值和触 ...
- Install Orace 11g on Solaris 10 Sparc 64 bit
昨天有一个客户端安装11g数据库.整个安装过程和一些遇到的问题是一个创纪录.共享. 由于客户不能使用自己的机器远程连接到server,意通过U盘.移动硬盘等拷贝不论什么文件.因此一些记录内容无法做到非 ...
- SDUT 2498-AOE网上的关键路径(spfa+字典序路径)
AOE网上的关键路径 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 一个无环的有向图称为无环图(Directed Acycl ...
- C语言求素数的算法
前言 最后一次是出了素数的问题C语言解决题目(面试),当时用了最粗暴的算法.回来细致參考资料,事实上答案有非常多种: 1,小学生版本号: 推断 x 是否为质数,就从 2 一直算到 x-1. stati ...
- nmap 使用注意事项
1.可行的网络主机的高速发现 nmap -sP 192.168.1.* 要么 nmap -sP 192.168.1.-254 2.扫描UDPport DP扫描方式用于推断UDPport的情况. 向目 ...
- crm创建报告补充导航
报告导航实现动态交互体验报告. 通过使用各种类型的操作的,报告允许用户导航到特定的报告.Microsoft Dynamics CRM 记录或其它网站 动态钻取到 Microsoft Dynamics ...
- Rational Rose 2007使用小结
1.Rose怎样隐藏类的属性和操作? 右击类,选Options->Suppress Attributes/Suppress Operations 2.Rose怎样表示类的约束? 在工具箱中选AB ...
- c# webbrowser 获取用户选中文字
原文:c# webbrowser 获取用户选中文字 最近一直被一个问题困扰,有一个文本框,一个webbrowser控件,一个上下文菜单, webbrowser 获取用户选中文字" tit ...
- Poj Roadblocks(次短路)
Description Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best ...
- 多重集组合数 (DP)
输入: n=3 m=3 a={1,2,3} M=10000 输出: 6 (0+0+3,0+1+2,0+2+1,1+0+2,1+1+1,1+2+0) 为了不重复计数,同一种类的物品最好一次性处理好.于 ...