50WA求救
查看原帖
50WA求救
741633
Ryanhao楼主2023/8/25 14:04
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n,m,a[405][405];
struct node {
	int x,y,z;
};
int xx[] = {1,2,2,1,-1,-2,-2,-1};
int yy[] = {2,1,-1,-2,2,1,-1,-2};
signed main() {
	std::ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//in*****************************************************************************************************
	int n,m,x,y;
	cin >> n >> m >> x >> y;
	
	//BFS****************************************************************************************************
	memset(a,-1,sizeof(a));
	a[x][y] = 0;
	queue<node>q;
	q.push({x,y,0});
	while(!q.empty()) {
		node f = q.front();
		q.pop();
		for (int i = 0; i < 8; i++) {
			int nx = f.x+xx[i];
			int ny = f.y+yy[i];
			if (nx < 1 || nx > n || ny < 1 || ny > m || a[nx][ny] != -1) continue;
			q.push({nx,ny,f.z+1});
			a[nx][ny] = f.z+1;
		}
	}
	
	//out****************************************************************************************************
	for (int i = 1; i <= n; i++) {
		for (int j = 1;  j <= m; j++) {
			printf("%-5d",a[i][j]);
		}
		cout << endl;
	}
	return 0;
}

哪里错了?

2023/8/25 14:04
加载中...