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 ...
随机推荐
- Nginx/LVS/HAProxy负载均衡软件的优缺点
一般对负载均衡的使用是随着网站规模的提升根据不同的阶段来使用不同的技术.具体的应用需求还得具体分析,如果是中小型的Web应用,比如日PV小于1000万,用Nginx就完全可以了:如果机器不少,可以用D ...
- 【转】java:Session(会话)机制详解
书中讲:以下情况,Session结束生命周期,Servlet容器将Session所占资源释放:1.客户端关闭浏览器2.Session过期3.服务器端调用了HttpSession的invalidate( ...
- ndk编译android的lame库
1.lame c库: https://github.com/intervigilium/liblame 下载后解压,进入目录,terminal里运行ndk-build即可 2.lame android ...
- OpenStack网络详解
本博客已经添加"打赏"功能,"打赏"位置位于右边栏红色框中,感谢您赞助的咖啡. Openstack需要对网络有一些了解才能进入openstack的世界,很多都是 ...
- 用AT命令调试调制解调器
最早生产调制解调器的公司是贺氏,后来组建的厂家制造的调制解调器都与HAYES兼容,大部分的通信软件使用菜单来对调制解调器进行配置.检测.但是有些通信软件要求用户直接发命令给调制解调器,在这种情况下必须 ...
- Packetbeat协议扩展开发教程(1)
Packetbeat ( https://www.elastic.co/products/beats/packetbeat )是一个开源的网络抓包与分析框架,内置了很多常见的协议解析,如HTPP.My ...
- spring-boot 学习笔记一
参考博客:https://www.cnblogs.com/ityouknow/p/5662753.html 1.构建项目: 访问http://start.spring.io/,下载demo: 下载解压 ...
- svn和git的优缺点
git官网api: https://git-scm.com/docs 一. 集中式vs分布式 1. Subversion属于集中式的版本控制系统集中式的版本控制系统都有一个单一的集中管理的服务器,保存 ...
- 大话FLASH和EEPROM
最近在看代码的时候,遇到了一个使用FLASH模拟EEPROM的情况,看到这个我当时是一脸蒙蔽啊,对于一个有时候连FLASH和EEPROM都分不清的人来说,怎么可能读懂用FLASH来模拟EEPROM呢? ...
- [ZT] matlab中plot画图参数的设置
一.Matlab绘图中用到的直线属性包括: (1)LineStyle:线形 (2)LineWidth:线宽 (3)Color:颜色 (4)MarkerType:标记点的形状 (5)MarkerSize ...