structpoint { int x; int y; boolisValid()const{ return x > 0 && x <= n && y > 0 && y <= m && area[x][y] == -1; } }; point steps[8] = {{-1,2},{1,2},{2,1},{2,-1},{1,-2},{-1,-2},{-2,-1},{-2,1}}; queue<point> tasks;
intmain(){ int x, y; scanf("%d%d%d%d", &n, &m, &x, &y); point cur = {x, y}, from; memset(area, -1, sizeof(area)); area[x][y] = 0; tasks.push(cur); while (!tasks.empty()) { from = tasks.front(); tasks.pop(); for (int i = 0; i < 8; ++i) { point to = {from.x + steps[i].x, from.y + steps[i].y}; if (to.isValid()) { area[to.x][to.y] = area[from.x][from.y] + 1; tasks.push(to); } } } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) printf("%d\t", area[i][j]); printf("\n"); } return0; }