/*
I didn't understand the question at the beginning. It turned out to be a question about horse jumping in chess. Didn't you like playing chess? But why... Tangle
This is my first self-written BFs. After debugging, I finally changed my low-level problem (marked)
*/
# Include <iostream> // 2374758 2010-04-23 14:41:15 accepted 1372 46 Ms 292 K 1189 B C ++ regret
# Include <queue>
# Include <cstdio>
Using namespace STD;
Int map [10] [10];
Bool hash [10] [10];
Int Si, SJ;
Int EI, EJ;
Char str1 [5];
Char str2 [5];
Int dir [8] [2] = {-1,-2}, {-2,-1}, {-2, 1}, {-1, 2 }, {1, 2}, {2, 1}, {2,-1}, {1,-2 }};
Struct Node
{
Int X;
Int y;
Int T;
};
Int BFS (int I, Int J)
{
Node P, N;
Int K;
N. x = I; N. Y = J; N. T = 0;
Queue <node> q;
Q. Push (N );
Hash [I] [J] = false;
While (! Q. Empty ())
{
N = Q. Front ();
Q. Pop ();
If (N. x = EI & N. Y = EJ)
{
Cout <"to get from" <str1 <"to" <str2 <"takes" <N. T <"knight moves." <Endl;
// Cout <N. T <Endl;
Break;
}
For (k = 0; k <8; k ++)
{
Int Tx = n. x + dir [k] [0];
Int ty = n. Y + dir [k] [1];
If (TX> = 1 & TX <= 8 & ty> = 1 & ty <= 8 & hash [TX] [ty]) // mark errors at the beginning and write them accidentally! Hash [TX] [ty]
{
P. x = TX;
P. Y = ty;
P. t = n. t + 1;
Q. Push (P );
Hash [p. x] [P. Y] = false;
}
}
}
Return 1;
}
Int main ()
{
While (scanf ("% S % s", str1, str2 )! = EOF)
{
SI = str1 [1]-'0 ';
SJ = str1 [0]-96; // @ at the beginning, enter SJ = str1 [0]-'0'-96. After debugging, the SJ value turns to a negative number.
Ei = str2 [1]-'0 ';
EJ = str2 [0]-96;
Memset (hash, true, sizeof (hash ));
BFS (Si, SJ );
// Cout <Endl;
}
}