# Include <iostream> # include <stdio. h> # include <string. h >#include <queue> using namespace STD; # define Maxx 45 char map [Maxx] [Maxx] [Maxx]; int vis [Maxx] [Maxx] [Maxx]; int dir [6] [3] = {, 0}, {-, 0}, {0, 0}, {0,-}, {0, 0, 1 },{,-1 }}; // int dir [6] [3] = {(, 0), (-, 0, 0), (0,-), (, 1), (,-1 )}; /// here, I'm wa for an unlimited number of times ~~~~~~~~~~~ Int L, R, C; struct node {int x, y, z; int step ;}; int BFS (INT Si, int SJ, int SK) {queue <node> q; while (! Q. empty () Q. pop (); memset (VIS, 0, sizeof (VIS); node cur, next; cur. z = Si, cur. X = SJ, cur. y = Sk, cur. step = 0; vis [Si] [SJ] [SK] = 1; q. push (cur); While (! Q. empty () {cur = Q. front (); q. pop (); For (INT I = 0; I <6; I ++) {next. z = cur. Z + dir [I] [0]; next. X = cur. X + dir [I] [1]; next. y = cur. Y + dir [I] [2]; next. step = cur. step + 1; if (next. z <1 | next. z> L | next. x <1 | next. x> r | next. Y <1 | next. y> C | map [next. z] [next. x] [next. y] = '#') continue; If (Map [next. z] [next. x] [next. y] = 'E') return next. step; If (! Vis [next. z] [next. x] [next. y]) {vis [next. z] [next. x] [next. y] = 1; q. push (next) ;}}return 0 ;}int main () {int Si, SJ, SK; while (scanf ("% d", & L, & R, & C), L, R, c) {for (INT I = 1; I <= L; 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') {Si = I; SJ = J; SK = K ;}} int ans = BFS (Si, SJ, SK); If (ANS = 0) printf ("trapped! \ N "); else printf (" escaped in % d minute (s). \ n ", ANS);} return 0 ;}
Time limit:1000 MSMemory limit:65536 KB
64-bit integer Io format:% I64d, % i64uJava class name:Main
[Submit] [Status] [discuss]
Descriptionyou 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? Inputthe 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 '. '. 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. outputeach 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 5S.....###..##..###.#############.####...###########.#######E1 3 3S###E####0 0 0
Sample output
Escaped in 11 minute (s). Trapped!
Question: starting point E of 3D space S end point # do not perform the same minimum steps, so it is still widely searched.
Similar to two-dimensional dashboard ~~~~~~~~
Poj 2251 Dungeon Master