150002 - Knight Moves

通过次数

1

提交次数

1

时间限制 : 1 秒
内存限制 : 128 MB

你的一个朋友正在研究旅行骑士问题(Traveling Knight Problem),在那里你可以找到一个最短的骑士移动路线,棋盘上每个方格只能经过一次。他认为问题中最困难的部分是确定两个给定方格之间的最小骑士移动次数,一旦完成了这一点,就很容易找到路线。

你的工作是编写一个程序,将两个坐标a和b作为输入,然后确定骑士在从a到b的最短路径上移动的次数。

输入

输入文件将包含一个或多个测试用例。每个测试用例由一行组成,其中包含两个由一个空格分隔的坐标。坐标是由一个字母(a..h)和一个数字(1..8)组成的字符串,字母(a.h)表示棋盘上的列,数字(1...8)代表棋盘上的行。

输出

对于每个测试用例,打印一行‘To get from xx to yy takes n knight moves.’.

样例

输入

e2 e4
a1 b2
b2 c3
a1 h8
a1 h7
h8 a1
b1 c3
f6 f6

输出

To get from e2 to e4 takes 2 knight moves.
To get from a1 to b2 takes 4 knight moves.
To get from b2 to c3 takes 2 knight moves.
To get from a1 to h8 takes 6 knight moves.
To get from a1 to h7 takes 5 knight moves.
To get from h8 to a1 takes 6 knight moves.
To get from b1 to c3 takes 1 knight moves.
To get from f6 to f6 takes 0 knight moves.

来源

UVA-439