为什么全RE
查看原帖
为什么全RE
1100290
SZC_1v99楼主2024/10/8 21:16
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct coord{
	int xx, yy;
};
queue<coord> q;
int ans[410][410];
int dir[8][2] = {
	2, 1,
	1, 2,
	-1, 2,
	-2, 1,
	-2, -1,
	-1, -2,
	1, -2,
	2, -1
};
int n, m, x, y;
signed main(){
	cin >> n >> m >> x >> y;
	memset(ans, -1, sizeof(ans));
	coord tmp = {x, y};
	q.push(tmp);
	ans[x][y] = 0;
	while(!q.empty()){
		coord u = q.front();
		int ux = u.xx, uy = u.yy;
		q.pop();
		for(int i = 0;i < 8;i++){
			int sx = ux + dir[i][0], sy = uy + dir[i][1];
			int b = ans[ux][uy];
			if(x < 1 || x > n || y < 1 || y > m || ans[sx][sy] != -1) continue;
			ans[sx][sy] = b + 1;
			coord tmp = {sx, sy};
			q.push(tmp);
		}
	}
	for(int i = 1;i <= n;i++){
		for(int j = 1;j <= m;j++){
			printf("%-5d", ans[i][j]);
		}
		printf("\n");
	}
	
	return 0;
} 
2024/10/8 21:16
加载中...