错了……
查看原帖
错了……
175149
Bean233楼主2023/4/19 13:21
#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
using namespace std;
int map[500][500];
int n,m;
int m1[9] = {0,1,2,-1,-2,1,2,-1,-2};
int m2[9] = {0,2,1,2,1,-2,-1,-2,-1};
int X,Y;
int bps(int x,int y,int step)
{
	//cout << step << " ";
	queue<int> qx,qy,q1x,q1y;
	for(int i=1;i<=8;i++)
	{
		qx.push(x+m1[i]);
		qy.push(y+m2[i]);
	}
	while(1)
	{
		if(qx.empty())
			break;
		int mx=qx.front(),my=qy.front();
		qx.pop();qy.pop();
		if(map[mx][my]==0 && (mx!=X||my!=Y))
		{
			if(mx<=n && mx>=1 && my>=1 && mx<=m) 
			{
				q1x.push(mx);q1y.push(my);
				map[mx][my] = step;
			}
		}
	}
	while(1)
	{
		if(q1x.empty())
			break;
		bps(q1x.front(),q1y.front(),step+1);
		q1x.pop();q1y.pop();
	}
	return 0;
}
int main()
{
	int x,y;
	cin >> n >> m >> x >> y;
	map[x][y]=0;
	X=x;Y=y;
	bps(x,y,1);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			cout << map[i][j] << " ";
		}
		cout << endl;
	}
	
	return 0;
}
2023/4/19 13:21
加载中...