POJ:Dungeon Master(三维bfs模板题)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 16748 | Accepted: 6522 |
Description
Is an escape possible? If yes, how long will it take?
Input
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
Escaped in x minute(s).
where x is replaced by the shortest time it takes to escape.
If it is not possible to escape, print the line
Trapped!
Sample Input
3 4 5
S....
.###.
.##..
###.# #####
#####
##.##
##... #####
#####
#.###
####E 1 3 3
S##
#E#
### 0 0 0
Sample Output
Escaped in 11 minute(s).
Trapped!
题解:
就是很裸的模板题,细心就好。其中'S'是起点,‘E’是终点,‘#’不能走。
#include <iostream>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <queue>
using namespace std;
char map[][][];
int fx[]= {,-,,,,};
int fy[]= {,,,-,,};
int fz[]= {,,,,,-};
struct node
{
int ans;
int x,y,z;
};
struct node t,f;
int v[][][];
int n,m,k;
void bfs(int xx,int yy,int zz)
{
memset(v,,sizeof(v));
queue<node>q;
t.x=xx;
t.y=yy;
t.z=zz;
t.ans=;
q.push(t);
v[t.x][t.y][t.z]=;
while(!q.empty())
{
t=q.front();
q.pop();
if(map[t.x][t.y][t.z]=='E')
{
printf("Escaped in %d minute(s).\n",t.ans);
return ;
}
for(int i=; i<; i++)
{
f.x=t.x+fx[i];
f.y=t.y+fy[i];
f.z=t.z+fz[i];
if(f.x>=&&f.x<n&&f.y>=&&f.y<m&&f.z>=&&f.z<k&&v[f.x][f.y][f.z]==&&map[f.x][f.y][f.z]!='#')
{
v[f.x][f.y][f.z]=;
f.ans=t.ans+;
q.push(f);
}
}
}
printf("Trapped!\n");
return ;
}
int main()
{
int xx,yy,zz;
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
if(n==&&m==&&k==) break;
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
scanf("%*c%s",map[i][j]);
}
}
for(int i=; i<n; i++)
{
for(int j=; j<m; j++)
{
for(int z1=; z1<k; z1++)
{
if(map[i][j][z1]=='S')
{
xx=i;
yy=j;
zz=z1;
break;
}
}
}
}
bfs(xx,yy,zz);
}
return ;
}
POJ:Dungeon Master(三维bfs模板题)的更多相关文章
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- POJ 2251 Dungeon Master (三维BFS)
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- ZOJ 1940 Dungeon Master 三维BFS
Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Desc ...
- Dungeon Master(三维bfs)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- POJ 2251 Dungeon Master【三维BFS模板】
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45743 Accepted: 17256 Desc ...
- 【POJ - 2251】Dungeon Master (bfs+优先队列)
Dungeon Master Descriptions: You are trapped in a 3D dungeon and need to find the quickest way out! ...
- POJ - 2251 Dungeon Master 【BFS】
题目链接 http://poj.org/problem?id=2251 题意 给出一个三维地图 给出一个起点 和 一个终点 '#' 表示 墙 走不通 '.' 表示 路 可以走通 求 从起点到终点的 最 ...
- POJ 2251 三维BFS(基础题)
Dungeon Master Description You are trapped in a 3D dungeon and need to find the quickest way out! Th ...
随机推荐
- 【大数据系列】HDFS文件权限和安全模式、安装
HDFS文件权限 1.与linux文件权限类型 r:read w:write x:execute权限x对于文件忽略,对于文件夹表示是否允许访问其内容 2.如果linux系统用户sanglp使用hado ...
- scanf printf sprintf fprintf
都是C语言中的函数,但C++保留了这些函数,在头文件iostream中声明了. 1 scanf(格式控制,输出列表) printf (格式控制,输出列表) 举例: #include <iostr ...
- 让A超链接无效的办法 阻止元素发生默认的行为
$("a").click(function(event){ event.preventDefault(); }); event.preventDefault(); 方法阻止元素发生 ...
- rman 中遇到 ORA-01861
RMAN> run{ 2> sql 'alter session set nls_date_format="yyyy-mm-dd hh24:mi:ss"'; 3> ...
- Elasticsearch学习之深入搜索六 --- 平衡搜索结果的精准率和召回率
1. 召回率和精准度 比如你搜索一个java spark,总共有100个doc,能返回多少个doc作为结果,就是召回率,recall 精准度,比如你搜索一个java spark,能不能尽可能让包含ja ...
- cocos2d-x-lua如何导出自定义类到lua脚本环境
这篇教程是基于你的工程是cocos2d-x-lua的项目,我假设你已经完全驾驭cocos-x/samples/Lua/HelloLua工程,基本明白lua和c++互调的一些原理. 我们的目的是要在 ...
- Docker关联使用的一些工具:Clip名字服务(转载)
Clip名字服务 Clip(http://blog.puppeter.com/read.php?7)是一个名字服务C/S架构,它将传统的IP管理维度替换为名字服务即有意义可记忆的String.Clip ...
- jquery的ajax()函数中文传值出现乱码完美解决方案
1. jquery的ajax()函数 $.ajax({ type: "POST", dataType: "text", url: ".. ...
- Centos 密钥登录系统
有两台机器一直放在IDC 机房一直没怎么正式使用,今天突然说一个项目要上线,于是赶紧配置好环境,做一些权限控制,之前一直使用的是密码登录,现在正式使用公开了,密码登录方式肯定不安全,于是按照之前的方法 ...
- zabbix中文乱码的问题
在使用zabbix时,有时候会出现中文乱码的问题,如下: 因为zabbix自身对中文简体的支持不完善,需要我们手动的去上传新的字体进行替换: 1.在windows获取字体库文件 在Windows上的字 ...