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 ...
随机推荐
- Android布局管理器(表格布局)
表格布局有TableLayout所代表,TableLayout继承了LinearLayout,因此他的本质依然是LinearLayout. 表格布局采用行.列的形式来进行管理,在使用的时候不需要声明多 ...
- ajax 操作全局监测,用户session失效
jQuery(function ($) { // 备份jquery的ajax方法 var _ajax = $.ajax; // 重写ajax方法,先判断登录在执行success函数 $.ajax = ...
- SGU 226.Colored graph(最短路)
时间限制:0.25s 空间限制:4M 题意: 给出一个n个节点,m条边的图,每条边都有标记了编号为1,2,3三种颜色之一,现在求从1号节点到n号节点的一条最短路径的长度,要求该路径中相邻的边没有相同的 ...
- javascript--”原路返回“
css代码: <style type="text/css"> * { margin: 0px; padding: 0px; font-family: "mic ...
- 计算机天才Aaron Swartz 名作 《如何提高效率》——纪念真正的“hacker"!
如何提高效率 <HOWTO: Be more productive>(如何提高效率)作者:Aaron Swartz 肯定有人跟你说过这样的话,“你有看电视的那么长时间,都可以用来写一本书了 ...
- JQuery 绑定回车事件 兼容ie8,ie9
$("#form-search").find('#search-query').bind('keypress', function(e) { var keycode; if(win ...
- grunt live
{ "name": "grunt-live-test", "version": "0.1.0", "autho ...
- 获取IP城市
新浪的接口 : http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 多地域测试方法:http://int.dpool.sina. ...
- Javascript中null值,特别注意的两点
null 是一个javascript字面量,表示空值,就是没有对象被呈现.他是javascript原始值之一.null值常被放在期望一个对象上,但是不引用任何对象的参数位置,也就是说对象的初始化. 我 ...
- CSS3 :nth-child() 选择器
CSS3 :nth-child() 选择器 代码: <!DOCTYPE html> <html> <head> <style> p:nth-child( ...