#include<bits/stdc++.h>
using namespace std;
int a[501][501];
int d[8][2]={{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
int h[20001][2];
int n,m,s,t;
void bfs(int p,int q)
{
int t=0,w=1;
h[1][0]=p;
h[1][1]=q;
a[p][q]=0;
while(t<w)
{
t++;
for(int i=0;i<8;i++)
{
int x,y;
x=h[t][0]+d[i][0];
y=h[t][1]+d[i][1];
if(a[x][y]==-1&&x>=1&&x<=n&&y>=1&&y<=m)
{
w++;
h[w][0]=x;
h[w][1]=y;
a[x][y]=a[h[t][0]][h[t][1]]+1;
}
}
}
}
int main()
{
memset(a,-1,sizeof(a));
cin>>n>>m>>s>>t;
bfs(s,t);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cout<<left<<setw(5)<<a[i][j];
}
cout<<endl;
}
return 0;
}
似乎也没什么不对
求助大佬