#include<stdio.h>
#include<iostream>
#include<string.h>
#include<memory.h>
using namespace std;
int xx[]={1,1,2,2,-1,-1,-2,-2};
int yy[]={2,-2,1,-1,2,-2,1,-1};
int map[8][8];
char a[13],b[13];
void dfs(int x,int y,int step)
{
if(x<0||y<0||x>7||y>7||step>=map[x][y]) return;
map[x][y]=step;
int i;
for(i=0;i<8;i++)
dfs(x+xx[i],y+yy[i],step+1);
}
int main()
{
while(scanf("%s%s",a,b)!=EOF)
{
memset(map,10,sizeof(map));
dfs(a[0]-'a',a[1]-'1',0);
printf("To get from %s to %s takes %d knight moves.\n",a,b,map[b[0]-'a'][b[1]-'1']);
}
return 0;
}
poj 2243 Knight Moves
最新推荐文章于 2022-03-05 14:41:19 发布