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 ...
随机推荐
- evernote出现“Sync failed due to unexpected problem at server side”的问题
继上次的"Invalid username and/or password"问题之后,evernote又出现了“Sync failed due to unexpected prob ...
- Delphi系统托盘组件 TTrayIcon 简介
TTrayIcon 的主要属性: TrayIcon.Icon指定托盘图标, 有几种用法:1.设计时选择;2.把一个 TIcon 对象给它;3.使用当前程序图标: TrayIcon1.Icon := A ...
- SAP OTR 字段维护 更改SAP的字段翻译
维护系统文本字段:SOTR_EDIT TC:SE63 在SAP用户选择屏幕中,用鼠标选定一个栏位后按F1键,能够看到SAP对其详细解释,通常这样的解释文本分为两部分,一部分为标题, ...
- 转载:IntelliJ Idea 常用快捷键列表
IntelliJ Idea 常用快捷键列表 (http://www.open-open.com/lib/view/open1396578860887.html) Ctrl+Shift + Enter, ...
- ActiveNotifications
The NotificationManager can tell you how many notifications your application is currently showing. T ...
- 10 条提升 Android 性能的建议
About the Speaker: Boris Farber 每个人都知道一个 App 的成功,更这个 App 的性能体验有着很密切的关系.但是如何让你的 App 拥有极致性能体验呢?在 Droid ...
- 一道在知乎很火的 Java 题——如何输出 ab【转】
这是一个源自知乎的话题,原贴链接:一道百度的面试题,有大神会嘛? 虽然我不是大神,但我也点进去看了一下,思考了一会之后有了一些思路,然后去看其它人的答案的时候果然全都已经被各路大神们先想到并贴出来了, ...
- IP 转地址
1.需要 QQWry.Dat IP 地址数据库 2辅助类库 using System; using System.Collections.Generic; using System.IO; usin ...
- Asp.net页面使用showModalDialog时Postback弹出新页面解决办法
今天碰到一个让我一开始觉得莫名其妙的问题, 用window.showModalDialog打开一个.aspx文件,然后点击这个页面上一个button, 把页面的数据存入数据库之后,居然又打开一个这个页 ...
- cer, pfx 创建,并且读取公钥/密钥,加解密 (C#程序实现)
PKI技术(public key infrastructure)里面,cer文件和pfx文件是很常见的.通常cer文件里面保存着公钥以及用户的一些信息,pfx里面则含有私钥和公钥. 用makecert ...