你的一个朋友正在研究旅行骑士问题(TKP),在这个问题中,你要找到最短的骑士移动封闭行程,该行程恰好访问棋盘上给定的n个方格中的每个方格一次。他认为问题中最困难的部分是确定在两个给定方格之间最小的骑士移动次数,一旦你完成了这一任务,找到旅程就变得很容易了。你当然知道,反之亦然。所以你让他写一个程序来解决“困难”的部分。你的工作是编写一个程序,将两个方块a和b作为输入,然后确定从a到b的最短路径上的骑士移动次数。
输入
一个输入文件由一行包含两个空格分隔的方格组成。
方格是由字母(A ..h)和数字(1..8)组成的字符串,前者表示棋盘上的列,后者表示棋盘上的行。
输出
打印一行 ‘To get from xx to yy takes n knight moves.’.
例子
原题内容(英文)
A friend of you is doing research on the Traveling Knight Problem (TKP) where you are to find the
shortest closed tour of knight moves that visits each square of a given set of n squares on a chessboard
exactly once. He thinks that the most difficult part of the problem is determining the smallest number of
knight moves between two given squares and that, once you have accomplished this, finding the tour
would be easy. Of course you know that it is vice versa. So you offer him to write a program that solves
the ”difficult” part. Your job is to write a program that takes two squares a and b as input and then
determines the number of knight moves on a shortest route from a to b.
Input
• An input file consists of one line containing two squares separated by one space.
• A square is a string consisting of a letter (a..h) representing the column and a digit (1..8)
representing the row on the chessboard.
Output
Print one line saying ‘To get from xx to yy takes n knight moves.’.