题目链接

题目大意:

三维迷宫,搜索从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)的更多相关文章

  1. POJ2251 Dungeon Master —— BFS

    题目链接:http://poj.org/problem?id=2251 Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  2. BFS POJ2251 Dungeon Master

    B - Dungeon Master Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  3. hdu 2251 Dungeon Master bfs

    Dungeon Master Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17555   Accepted: 6835 D ...

  4. 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 ...

  5. POJ2251——Dungeon Master(三维BFS)

    和迷宫问题区别不大,相比于POJ1321的棋盘问题,这里的BFS是三维的,即从4个方向变为6个方向. 用上队列的进出操作较为轻松. #include<iostream> #include& ...

  6. Dungeon Master bfs

    time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u POJ 2251 Descriptio ...

  7. 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 ...

  8. [poj] Dungeon Master bfs

    Description You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is co ...

  9. poj 2251 Dungeon Master( bfs )

    题目:http://poj.org/problem?id=2251 简单三维 bfs不解释, 1A,     上代码 #include <iostream> #include<cst ...

随机推荐

  1. [PWA] 18. Clean the photo cache

    We cannot let photo always keep caching new data without clean the old data. If message is not displ ...

  2. OSChina 其中很重要的一类——RequestContext

    RequestContext 这个类在 OSChina 中是很重要的一个类.该类由全局 Filter 进行初始化.并传递给包含 Action 和 页面中直接使用.使用时通过 RequestContex ...

  3. phpcms如何嵌套循环

    PHPCMS V9的标签制作以灵活见长,可以自由DIY出个性的数据调用,对于制作有风格有创意的网站模板很好用,今天就介绍一个标签循环嵌套方法,可以实现对PC标签循环调用,代码如下: 在此文件里/php ...

  4. Junit使用教程(一)

    几乎所有程序员都听说过Junit的大名,但不知真正懂得运用它的人有多少,我便是其中的一个小白. 知道Junit是用来测试的,但却把“宝刀”当成了“菜刀”用.为了从此不再菜鸟,特此总结整理了下Junit ...

  5. [转] Linux下查看文件和文件夹大小

    当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择. df可以查看一级文件夹大小.使用比例.档案系统及其挂入点,但对文件却无能为力.    du可以查看文件及文件夹的大小. ...

  6. UIDevice 系统信息详解

    获取当前设备    //获取当前设备    UIDevice *dev = [UIDevice currentDevice]; 设备和系统基本信息    NSLog(@"设备名称:%@&qu ...

  7. HDU5289

    题意:求解存在最大差值小于给定K值的所有区间段. 输入: T(测试数据) n(数组个数)K(给定区间值的范围) ai...(数组值) 输出: ss(所有满足符合条件的区间段) 思路:二分+ST算法,首 ...

  8. cancel-ng-swipe-right-on-child

    <!DOCTYPE html> <html lang="en" ng-app="myapp"> <head> <met ...

  9. css.day05

    1. 外边距合并  不是bug  而是一个特性  (以最大的那个边距为准) 两个盒子是并列关系 两个盒子 父子级关系 1. border 2.overflow:hidden; 3. padding  ...

  10. JavaScript省市联动

    <html> <head> <title>JS省市二级联动菜单,整理收集.</title> </head> <body bgcolor ...