“ Ctrl AC!一起 AC!”

题目:忘题戳这

分析:和普通的寻路一样,只要把地图的二维数组变成三维就可以

建议先做一下二维寻路再来写这题:参考博客某二维寻路题解

AC代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;
struct node {int r, c, z, step;//队列存放的坐标,和步数
};
char map[35][35][35];//地图
int visit[35][35][35];//访问记录
int sr, sz, sc, r, c, z;//起点和地图大小
int dx[] = { 0,1,-1,0,0,0 };
int dy[] = { 1,0,0,-1,0,0 };
int dz[] = { 0,0,0,0,1,-1 };
int bfs() {queue<node> q;node first;first.r = sr, first.c = sc, first.z = sz, first.step = 0;q.push(first);while (!q.empty()) {node temp = q.front(); q.pop();for (int i = 0; i < 6; i++) {//就是由四个方向变成了六个方向int nowr = temp.r + dx[i];int nowc = temp.c + dy[i];int nowz = temp.z + dz[i];int nowstep = temp.step + 1;//三种剪枝if (nowr<1 || nowr>r || nowc<1 || nowc>c || nowz<1 || nowz>z) continue;if (map[nowz][nowr][nowc] == '#') continue;if (visit[nowz][nowr][nowc]) continue;if (map[nowz][nowr][nowc]=='E') {return nowstep;}node next;next.r = nowr, next.c = nowc, next.z = nowz, next.step = nowstep;q.push(next);visit[nowz][nowr][nowc] = 1;}}return -1;
}
int main() {while (cin >> z >> r >> c && z && r && c) {memset(visit, 0, sizeof(visit));//初始化memset(map, '\0', sizeof(map));for (int i = 1; i <= z; i++) {for (int j = 1; j <= r; j++) {for (int k = 1; k <= c; k++) {cin >> map[i][j][k];if (map[i][j][k] == 'S') sz=i,sr=j,sc=k;//记录起点}}}int ans = bfs();if (ans == -1) cout << "Trapped!" << endl;else printf("Escaped in %d minute(s).\n", ans);}return 0;
}

感谢阅读!!!

“ Ctrl AC!一起 AC!”

POJ 1253:Dungeon Master相关推荐

  1. POJ 2251 Dungeon Master(三维BFS求最短路径)

    3D dungeon 时间限制: 1 Sec  内存限制: 128 MB 提交: 2  解决: 2 [提交][状态][讨论版][命题人:201506020829][Edit] [TestData] 题 ...

  2. POJ 2251 - Dungeon Master + Python实现

    原题连接:2251 -- Dungeon Master 参考资料:POJ 2251 - Dungeon Master | 眈眈探求 问题:从起点S,经上下左右前后行走,到达目的地E点,返回所经过的路径 ...

  3. 信息学奥赛一本通 1248:Dungeon Master | OpenJudge NOI 2.5 1253:Dungeon Master

    [题目链接] ybt 1248:Dungeon Master OpenJudge NOI 2.5 1253:Dungeon Master [题目翻译] 地牢城主 描述 你被困在一个3D地牢中,需要找到 ...

  4. 1253 Dungeon Master

    题目链接: http://noi.openjudge.cn/ch0205/1253/ http://poj.org/problem?id=2251 总时间限制: 1000ms  内存限制: 65536 ...

  5. poj 2251 Dungeon Master (三维bfs)

    http://poj.org/problem?id=2251 简单bfs,只不过是三维的... 唯一的坑点在输出上... Escaped in %d minute(s) 这意思是答案为1输出minut ...

  6. 1253:Dungeon Master

    描述 You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of ...

  7. POJ 2251 Dungeon Master

    题目链接:https://cn.vjudge.net/problem/POJ-2251 思路:简单BFS,只不过是由二维变成三维. 总结:BFS写起来还是不熟,有点费劲. AC代码: 1 #inclu ...

  8. POJ 2251 Dungeon Master (BFS最短路)

    三维空间里BFS最短路 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #incl ...

  9. Dungeon Master(地牢大师、底下城主)三维bfs

    1253:Dungeon Master(地牢大师.底下城主) 要敢于变通 和普通bfs的区别,仅仅在于数组开三维+搜索方向多了上下(现在的搜索方向是 上下东南西北) bfs多组输入要记得清空队列 // ...

最新文章

  1. 【lidar】基于YOLO的3D目标检测(激光雷达点云)课程设计
  2. 一文速览机器学习的类别(Python代码)
  3. python好用-Pyzo -- 好用的 Python 轻量级 IDE
  4. KDE/QT vs GNOME/GTK
  5. 3班的第二次模拟面试
  6. jedispool redis哨兵_Redis详解(九)------ 哨兵(Sentinel)模式详解
  7. python量化数据处理小细节(以后还会不断补充)
  8. 美图秀秀计算机教程,如何用美图秀秀换背景?美图秀秀换背景图文教程-电脑教程...
  9. BZOJ-4706 B君的多边形 OEIS
  10. 中国妇女儿童统计资料(2014-2020年)
  11. 计算机组成原理实验:基本运算器实验
  12. Struts 学习笔记之ActionForm
  13. oracle数据库单张表备份,oracle数据库如何备份一张表
  14. usb万能驱动win7_我!Win7!还能接着续!Z490 B460 H410 Win7 保姆教程
  15. mysql备份、还原数据库(命令行)
  16. 1号线彭埠站故障已经查明 是积水导致转辙机信号不良
  17. 微信小程序实现规划路线
  18. wifi发射功率查看和设置
  19. Karplus-Strong Algorithm 弦乐器模拟 吉他弦乐器发声原理 泛音 乐理概述
  20. 【收藏】六度分隔、六度空间(Six Degrees of Separation)理论

热门文章

  1. OA系统开发--springAOP理解
  2. 盲源分离matlab程序,分享一些盲源分离的代码及相关网址
  3. Spark和Hadoop书籍、学习视频网站推荐
  4. CAXA CAPP工艺图表2020中文版
  5. 计算机系微积分教材,清华大学出版社-图书详情-《大学数学(微积分)》
  6. 专家教你清除Rootkit
  7. 方正微型计算机U210,方正文祥u2!10怎么样
  8. 建立高效的测试团队 (转自关河)
  9. wowza 配置自己的VOD-Edge 实现一个vod点播
  10. 一步获取LeetCode的cookies