POJ2251 Dungeon Master(bfs)
题目链接。
题目大意:
三维迷宫,搜索从s到e的最小步骤数。
分析:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue> using namespace std; const int maxn = ; int dx[] = {, , -, , , };
int dy[] = {, , , , -, };
int dz[] = {-, , , , , }; char G[maxn][maxn][maxn];
bool vis[maxn][maxn][maxn];
int r, l, c; struct Pos {
int x, y, z;
int step;
}; int BFS(int x0, int y0, int z0) {
queue<Pos> Q; Q.push((Pos){x0, y0, z0, }); while(!Q.empty()) {
Pos e = Q.front(); Q.pop();
int x=e.x, y=e.y, z=e.z, s=e.step; if(G[z][x][y] == 'E') return s; for(int d=; d<; d++) {
int nx, ny, nz;
nx = x+dx[d];
ny = y+dy[d];
nz = z+dz[d]; if(nx < || ny < || nz < ) continue;
if(nx >= r || ny >= c || nz >= l) continue;
if(vis[nz][nx][ny]) continue;
if(G[nz][nx][ny] == '#') continue; vis[nz][nx][ny] = true; Q.push((Pos){nx, ny, nz, s+});
}
} return -;
} int main() {
int x0, y0, z0; while(scanf("%d%d%d", &l, &r, &c) == ) {
if(l == && r == && c == ) break; for(int i=; i<l; i++) {
for(int j=; j<r; j++) {
scanf("%s", G[i][j]);
}
} for(int i=; i<l; i++) {
for(int j=; j<r; j++) {
for(int k=; k<c; k++) {
if(G[i][j][k] == 'S'){
z0 = i; x0=j; y0=k;
}
}
}
} memset(vis, false, sizeof(vis)); int res = BFS(x0, y0, z0); if(res == -) {
printf("Trapped!\n");
}
else
printf("Escaped in %d minute(s).\n", res);
} return ;
}
POJ2251 Dungeon Master(bfs)的更多相关文章
- POJ2251 Dungeon Master —— BFS
题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total S ...
- BFS POJ2251 Dungeon Master
B - Dungeon Master Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u ...
- hdu 2251 Dungeon Master bfs
Dungeon Master Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 17555 Accepted: 6835 D ...
- 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 ...
- POJ2251——Dungeon Master(三维BFS)
和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...
- Dungeon Master bfs
time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...
- 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] Dungeon Master bfs
Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...
- poj 2251 Dungeon Master( bfs )
题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A, 上代码 #include <iostream> #include<cst ...
随机推荐
- Jupyter Notebook 对LaTeX 的支持
Jupyter的Markdown模式比我原来想想的更加强大:它支持LaTeX! 支持的特性不多,应该能满足一般的需求了.
- 在安装twincat plc时,出现 there are some files marked for deletion on next reboot.please reboot first then
在注冊表内"HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\ "中删除注冊表值 " ...
- 设置listview的header不能点击
View headView = inflater.inflate(R.layout.search_top, null); mListView.addHeaderView(headView ,null, ...
- ST表poj3264
/* ST表多次查询区间最小值 设 g[j][i] 表示从第 i 个数到第 i + 2 ^ j - 1 个数之间的最小值 类似DP的说 ans[i][j]=min (ans[i][mid],ans ...
- sql 列轉行、行轉列
PIVOT用于将列值旋转为列名(即行转列),在SQL Server 2000可以用聚合函数配合CASE语句实现 PIVOT的一般语法是:PIVOT(聚合函数(列) FOR 列 in (…) )AS P ...
- MySQL拷贝表的几种方式
假如我们有以下这样一个表: id username password ----------------------------------- 1 admin * ...
- [转] 与调试器共舞 - LLDB 的华尔兹
你是否曾经苦恼于理解你的代码,而去尝试打印一个变量的值? NSLog(@"%@", whatIsInsideThisThing); 或者跳过一个函数调用来简化程序的行为? NSNu ...
- cocos2dx 资源合并.
文件合并之前 文件合并之后 吐槽 我们项目比较奇葩, ui用cocostudio做, 这项光荣的任务由美术接手. 这个美术是个新手, 经过我长时间的观察, 她似乎不用怎么画画. 至少在很长一段时间里, ...
- 一个小玩具:NDK编译FFmpeg的例子
FFmpeg NDK编译 和最简单的APK 准备 硬件: 一台电脑,实验在Lenovo T430上 一个Android设备,实验在 三星S3/A7 编译环境: Ubuntu 14.04 (ant\ja ...
- uva 11673 Garbage Remembering Exam (概率)
题目链接: http://vjudge.net/problem/viewProblem.action?id=42000 该过程为随即过程,因此总期望值等于个单词对应的期望值,即它们wasted的概率 ...