题意:
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of unit cubes which may or may not be filled with rock. It takes one minute to move one unit north, south, east, west, up or down. You cannot move diagonally and the maze is surrounded by solid rock on all sides.
Is an escape possible? If yes, how long will it take?

Input
The input consists of a number of dungeons. Each dungeon description starts with a line containing three integers L, R and C (all limited to 30 in size).
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
Each maze generates one line of output. If it is possible to reach the exit, print a line of the form
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!

以前都是二位搜索,三维bfs就有上下左右前后六个位置,其他处理没区别。

import java.util.ArrayDeque;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;/**  0 1 1 0*  0 0 0 0*  0 0 0 0*  0 1 1 0*/
public class testB {static int xstart=0;static int ystart=0;static int hstart=0;static int xend=0;static int yend=0;static int hend=0;static int x1[]= {0,1,0,0,-1,0};//上下左右 前后static int y1[]= {1,0,0,-1,0,0};static int z1[]= {0,0,1,0,0,-1};public static void main(String[] args) {// TODO 自动生成的方法存根Scanner sc=new Scanner(System.in);while(sc.hasNext()){int l=sc.nextInt();//lever层数  hint r=sc.nextInt();//行  xint c=sc.nextInt();//列  yif(l==0&&r==0&&c==0)break;char map[][][]=new char[l][r][c];for(int i=0;i<l;i++){for(int j=0;j<r;j++){map[i][j]=sc.next().toCharArray();}
//              sc.next();}for(int i=0;i<l;i++){for(int j=0;j<r;j++){for(int k=0;k<c;k++){if(map[i][j][k]=='S'){xstart=j;ystart=k;hstart=i;}}// System.out.println();}//System.out.println("    ");}boolean jud[][][]=new boolean[l][r][c];Queue<node>q1=new ArrayDeque<node>();q1.add(new node(xstart, ystart, hstart,0));boolean b=false;int x,y,z=0;jud[hstart][xstart][ystart]=true;while(!q1.isEmpty()){node point=q1.poll();x=point.x;y=point.y; z=point.h;for(int i=0;i<6;i++){if(x+x1[i]<r&&x+x1[i]>=0&&y+y1[i]>=0&&y+y1[i]<c&&z+z1[i]>=0&&z+z1[i]<l)//没有越界{if(map[z+z1[i]][x+x1[i]][y+y1[i]]=='.'&&!jud[z+z1[i]][x+x1[i]][y+y1[i]]){q1.add(new node(x+x1[i], y+y1[i], z+z1[i], point.minitu+1));jud[z+z1[i]][x+x1[i]][y+y1[i]]=true;}else if(map[z+z1[i]][x+x1[i]][y+y1[i]]=='E'){System.out.println("Escaped in "+(point.minitu+1)+" minute(s).");b=true;break;}}}if(b)break;}if(!b){System.out.println("Trapped!");}}}   static Comparator<node>com=new Comparator<node>() {public int compare(node o1, node o2) {// TODO 自动生成的方法存根return (int)(o1.minitu-o2.minitu);}};}
class node{int x;int y;int h;int minitu;public node(int x,int y,int h, int minitu){this.x=x;this.y=y;this.h=h;this.minitu=minitu;}}
  • 如果对后端、爬虫、数据结构算法等感性趣欢迎关注我的个人公众号交流:bigsai

Dungeon Master(三维bfs)java相关推荐

  1. Dungeon Master 三维BFS

    三维BFS DungeonMasterDungeon\ MasterDungeon Master 跟二维没啥区别,就是方向多了几个,但在写的过程中出的bugbugbug还是蛮多的,所以记录一下吧! # ...

  2. poj 2251 Dungeon Master (三维bfs)

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

  3. Dungeon Master题解bfs

    Dungeon Master 题面翻译 题目描述 输入格式 输出格式 样例 #1 样例输入 #1 样例输出 #1 题解思路及TIME EXCEEDED问题 题解 超时题解(个人觉得没问题) 题面翻译 ...

  4. (POJ - 2251)Dungeon Master(bfs)

    题目链接:2251 -- Dungeon Master (poj.org) 这是一个典型的bfs迷宫问题,只不过是三维的,唯一需要注意的就是输入要用cin,不要用scanf,因为有换行,其他没什么了, ...

  5. Dungeon Master(poj2251,bfs)

    http://poj.org/problem?id=2251 http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=15203 Dun ...

  6. Dungeon Master(bfs)广度优先搜索

    描述 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【bfs】

    很基础的一道bfs /*这题是一个三维的迷宫题目,其中用'.'表示空地,'#'表示障碍物,'S'表示起点,'E'表示终点, 求从起点到终点的最小移动次数,解法和二维的类似, 只是在行动时除了东南西北移 ...

  8. pku 2251 Dungeon Master 基本BFS

    用了两种方式, 一种stl队列,一种自己实现的队列,事实证明stl就是好呀. stl万岁. #include <iostream> #include <queue> using ...

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

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

最新文章

  1. linux 新建用户配置文件 /etc/login.defs 简介
  2. 1642: [Usaco2007 Nov]Milking Time 挤奶时间(dp)
  3. 第二大数 滑动窗口 第九届“图灵杯”NEUQ-ACM程序设计竞赛个人赛
  4. HDU - 3966 Aragorn's Story(树链剖分)
  5. IE6-IE9兼容性问题列表及解决办法_补充之五:在IE9下, disabled的文本框内容被选中后,其他控件无法获得焦点问题...
  6. (王道408考研操作系统)第四章文件管理-第二节4:磁盘的管理
  7. HDU 3662 3D Convex Hull(三维凸包面的个数)
  8. 年薪20万的前端工程师成长线路指南!
  9. 功能详细设计文档模板
  10. 笔试 | 平安银行笔试题
  11. matlab的开方算法_matlab最大公约数 三种算法
  12. 玩转A2ZS,软改A4
  13. 计算机等级考试如何评改试题,全国计算机考试上机考试是如何改卷的
  14. Fast RTPS原理与代码分析(2):动态发现协议之参与者发现协议PDP
  15. TeamViewer15免费版更换账户登录设备
  16. SCSI与USB的关系
  17. 简体和繁体之间的转换
  18. 3DMax一个重要功能,通过它制作出来的影视作品有很强立体感
  19. 【黏住用户的不是小红书,而是它背后的那些人】
  20. 微信小程序 音乐播放控件,监听播放事件, 音乐播放的基本实现

热门文章

  1. C++ Primer 5th笔记(chap 13 拷贝控制) 实例2内存管理
  2. 设计模式--原型(Prototype)模式
  3. 【AI出牌器】第一次见这么“刺激”的斗地主,胜率高的关键因素竟是......
  4. 00-深入学习cache
  5. 两种方法设置html表格的宽高
  6. 2020-12-1(带你理解32位二进制搜索范围是4GB)
  7. 【安全漏洞】CVE-2021-32682 elFinder RCE 简单分析
  8. 014 怪物过滤的设计和实现
  9. 最强黑客库Blackbone使用教程
  10. 乞丐版HTML5播放器