/*************************************** * ********************************** File Name: poj2251two. cpp Author: yubo Mail: yuzibode@126.com Created Time: May 30, 2014 Friday 05 hours 11 minutes 28 seconds learning focus: Three-dimensional maze, focus on the queue application, I learned a lot! Come on! 3 4 5S ..... ###.. ##.. ###. #############. ####... ###########. ####### E1 3 3 S ### E ### 0 0 0 ****************** **************************************** * *************/# include
# Include
# Include
# Include
Using namespace std; int L, R, C; int S_x, S_y, S_z; char maze [40] [40] [40]; // mark map int dir [6] [3] = {-, 0,-, 0,-1 ,}; // array of 3D Orientation. Think about int vis [40] [40] [40]; typedef struct {int x, y, z; int depth; //} SE; int judge (int x, int y, int z) // self-written {if (x> = 0 & x
= 0 & y
= 0 & z
Q; SE q0, q1, q2; q0.x = I; q0.y = j; q0.z = k; q0.depth = 0; q. push (q0); while (! Q. empty () {q1 = q. front (); // read the first element to discard q in time. pop (); for (int I = 0; I <6; I ++) {int tmp1 = q1.x + dir [I] [0]; int tmp2 = q1.y + dir [I] [1]; int tmp3 = q1.z + dir [I] [2]; if (judge (tmp1, tmp2, tmp3 )&&! Vis [tmp1] [tmp2] [tmp3] & maze [tmp1] [tmp2] [tmp3]! = '#') {If (maze [tmp1] [tmp2] [tmp3] = 'E') {ans = q1.depth + 1; return;} q2.x = tmp1; q2.y = tmp2; q2.z = tmp3; q2.depth = q1.depth + 1; vis [tmp1] [tmp2] [tmp3] = 1; q. push (q2) ;}}} int main () {freopen ("in.txt", "r", stdin); char tmp; while (scanf ("% d", & L, & R, & C) {if (! L &&! R &&! C) break; memset (vis, 0, sizeof (vis); for (int I = 0; I
> Maze [I] [j] [k]; if (maze [I] [j] [k] = 's') {S_x = I; S_y = j; s_z = k ;}}ans =-1; bfs (S_x, S_y, S_z); if (ans! =-1) // The trap printf ("Escaped in % d minute (s). \ n", ans); elseprintf ("Trapped! \ N ");}}