大佬看下
查看原帖
大佬看下
270791
WanderingTrader楼主2020/5/2 13:59
#include<bits/stdc++.h>
using namespace std;
#define N 405
typedef struct node{
	int x,y,steps;
}A;
queue<A>q;
bool vis[N][N];
int ans[N][N],dx[10] = {-2,-2,-1,-1,1,1,2,2},dy[10] = {1,-1,2,-2,2,-2,1,-1};
int main(){
	int n,m,sx,sy;
	cin >> n >> m >> sx >> sy;
	q.push({sx,sy,0});
	memset(ans,-1,sizeof(ans));
	while(!q.empty()){
		A a = q.front();
		q.pop();
		if(a.x > n || a.y > m || a.x <= 0 || a.y <= 0 || vis[a.x][a.y])
			continue;
		vis[a.x][a.y] = 1;
		ans[a.x][a.y] = a.steps;
		for(int i = 0;i < 8;i ++)
			q.push({a.x + dx[i],a.y + dy[i],a.steps + 1});
	}
	for(int i = 1;i <= n;i ++,cout << endl)
	{
		cout << ans[i][1];
		for(int j = 2;j <= m;j ++)
			printf("%5d",ans[i][j]);
	}
	return 0;
}

这个纯属输出问题,大佬帮忙看下(如果是负数的话应该是负号在标准位置,数字在后,但是我这份变成了数字在标准位置,负号在前)

2020/5/2 13:59
加载中...