#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,x2,y2,use[30][30];
int way1[15]={0,-2,-2,-1,+1,+2,+2,+1,-1,-2,-2,+2,+2};
int way2[15]={0,-1,+1,+2,+2,+1,-1,-2,-2,+2,-2,-2,+2};
struct horse
{
int x,y,sum;
};
int bfs(int a,int b)
{
queue<horse>q;
q.push((horse){a,b,0});
while(!q.empty())
{
horse ans=q.front();
q.pop();
if(ans.x==1&&ans.y==1)return ans.sum;
//cout<<ans.sum<<endl;
for(int i=1;i<=12;i++)
{
horse w={ans.x,ans.y,ans.sum};
w.x+=way1[i];
w.y+=way2[i];
if(w.x>=1&&w.x<=20&&w.y>=1&&w.y<=20&&use[w.x][w.y]==0)
{
w.sum++;
use[w.x][w.y]=1;
q.push(w);
}
}
}
return -1;
}
int main(){
cin>>x>>y>>x2>>y2;
cout<<bfs(x,y)<<endl;
cout<<bfs(x2,y2);
return 0;
}
我的bfs可以求出正确答案,但只能调用一次,后面只能输出-1,为什么