java jmaster,Dungeon Master(三维bfs)java

题意:

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层数 h int r=sc.nextInt();//行 x int c=sc.nextInt();//列 y if(l==0&&r==0&&c==0)break; char map[][][]=new char[l][r][c]; for(int i=0;i

// sc.next(); } for(int i=0;iq1=new ArrayDeque(); 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]=0&&y+y1[i]>=0&&y+y1[i]=0&&z+z1[i]

}

static Comparatorcom=new Comparator() {

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;

}

}1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

如果对后端、爬虫、数据结构算法等感性趣欢迎关注我的个人公众号交流:bigsai

文章来源: bigsai.blog.csdn.net,作者:Big sai,版权归原作者所有,如需转载,请联系作者。

原文链接:bigsai.blog.csdn.net/article/details/87977751

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值