题目:
Description
在一个8*8的棋盘上,一只中国象棋中的马要从一个点跳到另一个点。问最少需要多少步。
Input
整个测试组由多组数据组成,请做到文件底结束。
对于每组数据,前两个坐标代表出发点,后两个代表结束点。注意坐标第一位为a至h中某个字母,第二位为1到8某个数字。
Output
对于每个测试请输出"To get from xx to yy takes n knight moves.".
Sample Input
e2 e4
a1 b2
b2 c3
a1 h8
a1 h7
h8 a1
b1 c3
f6 f6
Sample Output
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.
吐槽:
这道题目翻译过来是骑士移动,但在OJ上却变成了中国象棋的马,我也是很无语。
进入正题
思路:
简单的BFS搜索,马的八个方向搜下去即可。
#include <bits/stdc++.h>
using namespace std;
int sx,sy,ex,ey;
int dir[8][2]={
{
2,1},{
-2,1},{
2,-1},{
-2,-1