#include<bits/stdc++.h>
using namespace std;
int ma[9]={0,2,2,-1,1,-2,-2,-1,1},mb[9]={0,-1,1,2,2,-1,1,-2,-2};
int n,m,x,y;
void bfs(int z,int d){
if(z==x&&d==y){
cout<<0<<" ";
return ;
}
int q[400901][4];
q[1][1]=x;
q[1][2]=y;
q[1][3]=0;
int h=0,t=1;
while(h<=t){
h++;
for(int i=1;i<=8;i++){
int xx=q[h][1]+ma[i];
int yy=q[h][2]+mb[i];
if(xx<=n&&yy<=m&&xx>0&&yy>0){
t++;
q[t][1]=xx;
q[t][2]=yy;
q[t][3]=q[h][3]+1;
if(q[t][1]==z&&q[t][2]==d){
cout<<q[t][3]<<" ";
return ;
}
}
}
}
cout<<-1<<" ";
}
int main(){
cin>>n>>m;
cin>>x>>y;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
bfs(i,j);
}
cout<<endl;
}
}#include<bits/stdc++.h>
using namespace std;
int ma[9]={0,2,2,-1,1,-2,-2,-1,1},mb[9]={0,-1,1,2,2,-1,1,-2,-2};
int n,m,x,y;
void bfs(int z,int d){
if(z==x&&d==y){
cout<<0<<" ";
return ;
}
int q[400901][4];
q[1][1]=x;
q[1][2]=y;
q[1][3]=0;
int h=0,t=1;
while(h<=t){
h++;
for(int i=1;i<=8;i++){
int xx=q[h][1]+ma[i];
int yy=q[h][2]+mb[i];
if(xx<=n&&yy<=m&&xx>0&&yy>0){
t++;
q[t][1]=xx;
q[t][2]=yy;
q[t][3]=q[h][3]+1;
if(q[t][1]==z&&q[t][2]==d){
cout<<q[t][3]<<" ";
return ;
}
}
}
}
cout<<-1<<" ";
}
int main(){
cin>>n>>m;
cin>>x>>y;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
bfs(i,j);
}
cout<<endl;
}
}
#include<bits/stdc++.h> using namespace std; int ma[9]={0,2,2,-1,1,-2,-2,-1,1},mb[9]={0,-1,1,2,2,-1,1,-2,-2}; int n,m,x,y; void bfs(int z,int d){ if(z==x&&d==y){ cout<<0<<" "; return ; } int q[400901][4]; q[1][1]=x; q[1][2]=y; q[1][3]=0; int h=0,t=1; while(h<=t){ h++; for(int i=1;i<=8;i++){ int xx=q[h][1]+ma[i]; int yy=q[h][2]+mb[i]; if(xx<=n&&yy<=m&&xx>0&&yy>0){ t++; q[t][1]=xx; q[t][2]=yy; q[t][3]=q[h][3]+1; if(q[t][1]==z&&q[t][2]==d){ cout<<q[t][3]<<" "; return ; } } } } cout<<-1<<" "; } int main(){ cin>>n>>m; cin>>x>>y; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ bfs(i,j); } cout<<endl; } }#include<bits/stdc++.h> using namespace std; int ma[9]={0,2,2,-1,1,-2,-2,-1,1},mb[9]={0,-1,1,2,2,-1,1,-2,-2}; int n,m,x,y; void bfs(int z,int d){ if(z==x&&d==y){ cout<<0<<" "; return ; } int q[400901][4]; q[1][1]=x; q[1][2]=y; q[1][3]=0; int h=0,t=1; while(h<=t){ h++; for(int i=1;i<=8;i++){ int xx=q[h][1]+ma[i]; int yy=q[h][2]+mb[i]; if(xx<=n&&yy<=m&&xx>0&&yy>0){ t++; q[t][1]=xx; q[t][2]=yy; q[t][3]=q[h][3]+1; if(q[t][1]==z&&q[t][2]==d){ cout<<q[t][3]<<" "; return ; } } } } cout<<-1<<" "; } int main(){ cin>>n>>m; cin>>x>>y; for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ bfs(i,j); } cout<<endl; } }