```cpp
#include<iostream>
using namespace std;
const int maxn=54;
const int maxm=54;
bool vis[maxn][maxm];//访问
int pre[maxn][maxm],x1,y1,x2,y2,a[5005],b[5005];
int xx[13]={0,-2,-2,-2,-2,-1,1,2,2,2,2,1,-1};//马的方向,不要搞错
int yy[13]={0,-2,-1,1,2,2,2,2,1,-1,-2,-2,-2};
//广度优先搜索(bfs)
void bfs(){
int head=1,tail=1;
a[head]=1;
b[head]=1;
while(head<=tail){
for(int i=1;i<=12;i++){//每个方向走一遍
int h=a[head]+xx[i],l=b[head]+yy[i];
if(h<=maxn&&h>=1&&l<=maxm&&l>=1&&vis[h][l]==0){//检查是否越界
tail++;
a[tail]=h;
b[tail]=l;
vis[h][l]=1;
pre[h][l]=pre[a[head]][b[head]]+1;
if(pre[x1][y1]!=0&&pre[x2][y2]!=0){//是否都走过了
cout<<pre[x1][y1]<<endl<<pre[x2][y2]<<endl;
return;
}
}
}
head++;
}
}
int main(){
cin>>x1>>y1>>x2>>y2;//输入
//从(1,1)开始走,这样只要走一次(少打点字)
pre[1][1]=0;
bfs();
return 0;
}
```
by BGM114514 @ 2023-02-19 16:23:27