作业介绍

#include<bits/stdc++.h>
using namespace std;
int arr[501][501];
bool vis[501][501];
int n,m,sx,sy;      //n/m 行和列  sx/sy 起点的坐标  

struct pos{    // 代表每个点的位置    
	int x,y;
};

int ix[8] = {-2,-1,+1,+2,+2,+1,-1,-2};
int iy[8] = {-1,-2,-2,-1,+1,+2,+2,+1};

void bfs(){
	queue<pos> q;   
	pos start;
	start.x = sx;
	start.y = sy;
	q.push(start);   // 加入起点    
	vis[sx][sy] = 1; // 起点标记  
	
	while(!q.empty()){
		pos head = q.front();  
		for(int i=0;i<8;i++){
			int nx = head.x + ix[i];
			int ny = head.y + iy[i];
			if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&vis[nx][ny]==0){
				pos temp;
				temp.x = nx;
				temp.y = ny;
				q.push(temp);    //点合法,加入到队列中   
				vis[nx][ny] = 1; //标记 
				arr[nx][ny] = arr[head.x][head.y] + 1;
			}
		}
		q.pop();
		
	} 

}

int main(){
	
	cin >> n >> m >> sx >> sy;
	bfs();
	for(int i=1; i<=n; i++){
		for(int j=1; j<=m; j++){
			if(vis[i][j]==0){
				cout << left << setw(5) << "-1" ;
			} 
			else{
				cout << left << setw(5) <<arr[i][j];
			}
		}
		cout << endl;
	}	
	
	
	return 0;
}

状态
已结束
题目
5
开始时间
2025-3-9 0:00
截止时间
2025-3-10 23:59
可延期
24 小时