Common 3D wide search, please note thatInput:Columns, rows, and layers
# Include <iostream> # include <cstdio> # include <cstring> # include <queue> # include <algorithm> # define M 11 using namespace STD; int dir [6] [3] = {0, 0}, {0,-}, {, 0}, {-, 0}, {0, 0, 0, 1 },{,-1 }}; // six direction int vis [m] [m] [m]; char map [m] [m] [m]; int N, M, P, Sx, Sy, SZ, ex, ey, EZ; bool CK (int x, int y, int Z) {If (x> = 0 & x <n & Y> = 0 & Y <n & Z> = 0 & Z <n &&! Vis [Z] [x] [Y] & map [Z] [x] [Y] = 'O') return true; return false ;} struct node {int X, Y, Z, St;}; void BFS () {If (SX = ex & Sy = ey & SZ = EZ) {cout <n <"" <0 <Endl; return;} memset (VIS, 0, sizeof vis); queue <node> q; node A, B; a. z = SZ,. X = Sx,. y = Sy,. st = 0; vis [SZ] [SX] [sy] = 1; q. push (a); While (! Q. empty () {A = Q. front (), Q. pop (); For (INT I = 0; I <6; ++ I) {B. X =. X + dir [I] [0]; B. y =. Y + dir [I] [1]; B. z =. Z + dir [I] [2]; B. st =. st + 1; if (! CK (B. x, B. y, B. z) continue; If (B. X = ex & B. y = ey & B. z = EZ) {cout <n <"" <B. st <Endl; return;} vis [B. z] [B. x] [B. y] = 1; q. push (B) ;}} printf ("No route \ n"); Return ;}int main () {// freopen ("input.txt", "r", stdin ); // freopen ("output.txt", "W", stdout); While (scanf ("START % d", & N )! = EOF) {for (INT I = 0; I <n; ++ I) {for (Int J = 0; j <n; ++ J) {scanf ("% s", map [I] [J]) ;}} scanf ("% d", & Sy, & Sx, & SZ, & ey, & Ex, & EZ); char STR [10]; CIN> STR; getchar (); BFS () ;}return 0 ;} <span style = "color: # 3333ff;"> </span>