Question: 3D space. Given the start point and end point, the minimum number of steps is required.
Analysis: Generally, it is a bit difficult to read this graph and get dizzy.
# Include <iostream> # include <algorithm> # include <queue> using namespace STD; char map [11] [11] [11]; bool vis [11] [11] [11]; int dir [6] [3] = {, 0}, {-, 0, 0 },{ 0,-},{ 0, 1 },{ 0,-1 }}; int N, ans; int EI, J, EZ; struct node {int X, Y, Z, CNT; node (int A = 0, int B = 0, int C = 0, int D = 0): X (), Y (B), Z (C), CNT (d) {}}; void BFS (node f) {queue <node> q; q. push (f); node temp; while (! Q. empty () {temp = Q. front (); q. pop (); If (temp. X = EI & temp. y = EJ & temp. z = EZ) {ans = temp. CNT; return ;}for (int K = 0; k <6; k ++) {int x = temp. X + dir [k] [0]; int y = temp. Y + dir [k] [1]; int z = temp. Z + dir [k] [2]; if (x <0 | x> = n | Y <0 | Y> = n | z <0 | z> = n | Vis [x] [y] [Z] | map [x] [y] [Z] = 'X ') continue; vis [x] [y] [Z] = 1; q. push (node (X, Y, Z, temp. CNT + 1) ;}}int main () {char STR [10]; int Si, SJ, SZ; while (scanf ("% S % d", STR, & n) = 2) {for (int K = 0; k <n; k ++) for (INT I = 0; I <n; I ++) {getchar (); For (Int J = 0; j <n; j ++) {scanf ("% C ", & map [I] [J] [k]) ;}} scanf ("% d", & Si, & SJ, & sz ); scanf ("% d", & EI, & EJ, & EZ); scanf ("% s", STR); memset (VIS, 0, sizeof (VIS); vis [Si] [SJ] [SZ] = 1; node F = node (Si, SJ, SZ, 0); ans =-1; BFS (f); If (ANS =-1) puts ("No route"); else printf ("% d \ n", N, ANS );} return 0 ;}