球球大佬看看为啥全WA
查看原帖
球球大佬看看为啥全WA
982761
_zhiqi_楼主2024/7/29 15:27
#include<bits/stdc++.h>
using namespace std;
int sum[][2]= {{2,1},{2,-1},{-2,-1},{-2,1},{1,2},{1,-2},{-1,2},{1,2}};
int n,m,x,y,z;
queue<int>hang;
queue<int>lie;
const int N = 410;
struct node {
	int stepp;
	bool walk;
} num[N][N];
void bfs(int h,int l) {
	if(h < 1 || l < 1 || h > n || l > m || !num[h][l].walk) {
		return;
	}
	int i = 0;
	while(!hang.empty() && !lie.empty()) {
		hang.push(h);
		lie.push(l);
		int hh = hang.front(),ll = lie.front();
		num[hh][ll].stepp = num[h][l].stepp + 1;
		hang.pop();
		lie.pop();
		bfs(hh,ll);
	}
}
int main() {
	cin >> n >> m >> x >> y;
	bfs(x,y);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			cout << num[i][j].stepp << ' ';
		}
		cout << endl;
	}
	return 0;
}
2024/7/29 15:27
加载中...