无法运行
#include <bits/stdc++.h>
using namespace std;
int n,m,x,y,vis[405][405],num;
int f_x[8] = {-2,-2,2,2,1,-1,1,-1},f_y[8] = {-1,1,-1,1,2,-2,-2,2};
struct zb
{
int x;
int y;
};
queue <zb> q;
zb pos(int x,int y)
{
zb w;
w.x = x;
w.y = y;
return w;
}
void bfs()
{
while (!q.empty())
{
int x = q.front().x,y = q.front().y;
q.pop();
for (int i = 0;i < 8;i++)
{
if (vis[x + f_x[i]][y + f_y[i]] != -1 || vis[x + f_x[i]][y + f_y[i]] > vis[x][y] + 1)
{
q.push(pos(x + f_x[i],y + f_y[i]));
vis[x + f_x[i]][y + f_y[i]] = vis[x][y] + 1;
}
}
}
}
int main()
{
cin >> n >> m >> x >> y;
q.push(pos(x,y));
memset(vis,-1,sizeof(vis));
vis[x][y] = 0;
bfs();
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= m;j++)
{
cout << vis[i][j] << " ";
}
cout << endl;
}
return 0;
}