B - Dungeon Master
地牢大师(感觉像是一款游戏啊.......)
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; #define maxn 100 struct node
{
int x, y, z, step;
}; int h, m, n;//高,长和宽
//6个方向可以走
int dir[][] = { {,,},{-,,},{,,},{,-,},{,,},{,,-} };
char G[maxn][maxn][maxn]; int OK(int z, int x, int y)//判断这点是否可以走
{
if(z>=&&z<h && x>=&&x<m && y>=&&y<n && G[z][x][y] != '#')
return ;
return ;
}
int DFS(node s, node e)
{
queue<node> Q;
Q.push(s); while(Q.size())
{
s = Q.front();Q.pop(); if(s.x==e.x&&s.y==e.y&&s.z==e.z)
return s.step; for(int i=; i<; i++)
{
node q = s;
q.x += dir[i][];
q.y += dir[i][];
q.z += dir[i][];
q.step += ; if(OK(q.z, q.x, q.y) == )
{
G[q.z][q.x][q.y] = '#';
Q.push(q);
}
}
} return -;
} int main()
{
while(scanf("%d%d%d", &h, &m, &n), h+m+n)
{
int i, j, k;
node s, e; for(i=; i<h; i++)
for(j=; j<m; j++)
{
scanf("%s", G[i][j]);
for(k=; k<n; k++)
{
if(G[i][j][k] == 'S')
{
s.z = i;
s.x = j;
s.y = k;
s.step = ;
}
if(G[i][j][k] == 'E')
{
e.z = i;
e.x = j;
e.y = k;
}
}
} int ans = DFS(s, e); if(ans != -)
printf("Escaped in %d minute(s).\n", ans);
else
printf("Trapped!\n");
} return ;
}
B - Dungeon Master的更多相关文章
- POJ 2251 Dungeon Master(3D迷宫 bfs)
传送门 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 28416 Accepted: 11 ...
- poj 2251 Dungeon Master
http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- Dungeon Master 分类: 搜索 POJ 2015-08-09 14:25 4人阅读 评论(0) 收藏
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20995 Accepted: 8150 Descr ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- UVa532 Dungeon Master 三维迷宫
学习点: scanf可以自动过滤空行 搜索时要先判断是否越界(L R C),再判断其他条件是否满足 bfs搜索时可以在入口处(push时)判断是否达到目标,也可以在出口处(pop时) #i ...
- Dungeon Master poj 2251 dfs
Language: Default Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16855 ...
- POJ 2251 Dungeon Master(地牢大师)
p.MsoNormal { margin-bottom: 10.0000pt; font-family: Tahoma; font-size: 11.0000pt } h1 { margin-top: ...
- BFS POJ2251 Dungeon Master
B - Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- POJ 2251 Dungeon Master (非三维bfs)
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 55224 Accepted: 20493 ...
- 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 ...
随机推荐
- 从ActionFilterAttribute向view传送数据
[原文转载]http://www.cnblogs.com/QLeelulu/archive/2008/08/17/1269599.html 原文地址:ASP.NET MVC Tip #31 – Pas ...
- Word 中标题的编号变成黑框
问题: 在使用Word编写文档时,提前拟好的标题编号会突然变成黑框(黑色的方框,黑色的矩形),如下图 解决方案: 1.将光标定位到标题中,紧邻黑框的右侧 2.按键盘左方向键使方框变成黑色 4.按键盘的 ...
- MVC5+EF6 入门完整教程一
第0课 从0开始 ASP.NET MVC开发模式和传统的WebForm开发模式相比,增加了很多"约定". 直接讲这些 "约定" 会让人困惑,而且东西太多容易忘记 ...
- laravel4通过控制视图模板路劲来动态切换主题
通过控制视图模板路劲来动态切换主题 App::before(function($request) { $paths = Terminal::isMobile() ? array(__dir__.'/v ...
- Bootstrap_Javascript_提示框
一. 结构分析 在Bootstrap框架中的提示框,结构非常简单,常常使用的是按钮<button>标签或者链接<a>标签来制作.不管是使用按钮还是链接来制作提示框,他们都有一个 ...
- QTP10破解
1. 下载QTP10.0版本 http://h30302.www3.hp.com/prdownloads/T6510-15063.zip?ordernumber=380454070&itemi ...
- YII 验证邮箱和QQ号码
//验证邮箱非空,和邮箱格式 //验证邮箱非空,和邮箱格式 array("email","e ...
- Python Tutorial 学习(三)--An Informal Introduction to Python
3.1. 将Python用作计算器 3.1.1. Numbers 数 作为一个计算器,python支持简单的操作, '+','-','*','/'地球人都知道的加减乘除. ()可以用来改变优先级,同数 ...
- Problem:To Connect with MySQL in Virtual PC Environment
I'm trying to build a 1:n dev environment,with the help of Vsever(just like VMware worked on sever) ...
- 怎么用notepad配置来运行C语音环境
想要运行C语言,我们可以用notepad软件来进行编辑,那么怎么用notepad 配置运行c语言开发环境呢? Notepad++是一款很好的编辑器,可以用来开发很多的工具,具体大家请看下文给大家详细讲 ...