I used extensive search, and I have been searching questions for a few days. Then I found my feelings. This question has not changed much, but it has become three-dimensional.
<Code>
# Include <iostream>
# Include <queue>
Using namespace STD;
# Define size 15
Int N;
Char map [size] [size] [size];
Bool visit [size] [size] [size];
Int Sx, Sy, SZ;
Int ex, ey, EZ;
Int dir [6] [3] = {0,-1}, {, 1}, {0,-}, {, 0, 0 },{, 0 }};
Struct Node
{
Int x, y, z;
Int step;
} First, next;
Bool check (int z, int y, int X)
{
If (x> = 0 & x <n & Y> = 0 & Y <n & Z> = 0 & Z <n & map [Z] [y] [x] = 'O' & visit [Z] [y] [x] = 0)
Return true;
Return false;
}
Void BFS ()
{
Int I;
Queue <node> que;
Memset (visit, 0, sizeof (visit ));
First. x = SX;
First. Y = sy;
First. z = SZ;
First. Step = 0;
Que. Push (first );
Visit [first. Z] [first. Y] [first. x] = 1;
If (first. x = ex & first. Y = ey & first. z = EZ)
{
Cout <n <"" <0 <Endl;
Return;
}
While (! Que. Empty ())
{
First = que. Front ();
Que. Pop ();
For (I = 0; I <6; I ++)
{
Next. x = first. x + dir [I] [0];
Next. Y = first. Y + dir [I] [1];
Next. z = first. Z + dir [I] [2];
If (check (next. Z, next. Y, next. X ))
{
Visit [next. Z] [next. Y] [next. x] = 1;
Next. Step = first. Step + 1;
If (next. x = ex & next. Y = ey & next. z = EZ)
{
Cout <n <"" <next. Step <Endl;
Return;
}
Que. Push (next );
}
}
}
Cout <"No route" <Endl;
}
Int main ()
{
Int I, J, K;
Char T [10];
While (scanf ("% S % d", T, & N )! = EOF)
{
For (I = 0; I <n; I ++)
For (j = 0; j <n; j ++)
For (k = 0; k <n; k ++)
Cin> map [I] [J] [k];
Cin> SX> Sy> SZ;
Cin> ex> ey> EZ;
Cin> T;
Memset (visit, 0, sizeof (visit ));
BFS ();
}
Return 0;
}