10wa求助
查看原帖
10wa求助
255540
Her_Lingxiao楼主2020/6/12 13:25
#include <cstdio>
#include <cstring>
using namespace std;
int q[400 * 400 + 4][2];
int ans[410][410];
int head, tail;
int mx[8] = {2, -2, 2, -2, -1, 1, -1, 1};
int my[8] = {1, -1, -1, 1, 2, 2, -2 ,-2};
int main()
{
	memset(ans, -1, sizeof(ans));
	int a, b;
	int x, y;
	scanf("%d %d %d %d", &a, &b, &x, &y);
	q[1][0] = x;
	q[1][1] = y;
	head++;
	tail++;
	ans[x][y] = 0;
	while(head <= tail)
	{
		for(int i = 0; i < 8; i++)
		{
			int X = q[head][0] + mx[i];
			int Y = q[head][1] + my[i];
			if(X > a || Y > b || X <= 0 || Y <= 0)
				continue; 
			if(ans[x][y] == -1)
			{
				tail++;
				ans[X][Y] = ans[q[head][0]][q[head][1]] + 1;
				q[tail][0] = X;
				q[tail][1] = Y;
			}
		}
		head++;
	}
	for(int i = 1; i <= a; i++)
	{
		for(int j = 1; j <= b; j++)
		{
			printf("%d     ", ans[i][j]);
		}
		printf("\n");
	}
	
	return 0;
}
2020/6/12 13:25
加载中...