```c
#include<bits/stdc++.h>
#define CLOSE ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
int n,m,x,y;
int a[410][410];
queue<pair<int,int> > q;
void bfs(int x,int y){
q.push({x,y});
a[x][y]=0;
int dx[8]={2,1,-2,-1,2,1,-2,-1},dy[8]={1,2,-1,-2,-1,-2,1,2};
while(!q.empty()){
pair<int,int> t = q.front();
q.pop();
for(int i=0;i<8;i++){
int u=t.first+dx[i],d=t.second+dy[i];
if(u>=1&&u<=m&&d>=1&&d<=n&&a[u][d]==-1){
a[u][d] = a[t.first][t.second]+1;
q.push({u,d});
}
}
}
}
int main(){
cin>>n>>m>>x>>y;
memset(a,-1,sizeof(a));
bfs(x,y);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cout<<a[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
```
by scp049 @ 2022-04-07 20:31:24
洛谷机子炸了,代码没问题
by LFCode @ 2022-04-07 20:32:23
机子炸了
by Fast_IO @ 2022-04-07 20:33:26
把close那句删了可以过编译,但是全WA
by ssxvngn @ 2022-04-07 20:36:20
@[scp049](/user/149623) 洛谷判题机磁盘占满,挂了
by bmh_0704_chbzyx @ 2022-04-07 20:44:23
谢谢大佬们 现在果然是可以运行全WA了orz 我再改改
by scp049 @ 2022-04-09 22:30:12