各位大佬,求调QAQ
查看原帖
各位大佬,求调QAQ
1055670
pooh_mukuigumeng13楼主2024/11/23 16:23
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iomanip>
using namespace std;

int dx[8]={1,2,2,1,-1,-2,-2,-1};
int dy[8]={2,1,-1,-2,-2,-1,1,2}; 
int front=0,tail=0;

struct cz{
	int cs;
	bool visi;
}a[405][405];
struct qu{
	int h;
	int l;
}q[10005];


int main(){
	int l,h,x,y;
	cin>>l>>h>>x>>y;
	for (int i=1;i<=h;i++){
		for(int j=1;j<=l;j++){
			a[i][j].visi=1;
			a[i][j].cs=0;
		}
	}
	q[++tail].h=x;
	q[tail].l=y;
	a[x][y].visi=0;
	while(front<tail){
		front++;
		x=q[front].h;
		y=q[front].l;
		for (int i=0;i<=7;i++){
			int x1=x+dx[i];
			int y1=y+dy[i];
			if(a[x1][y1].visi){
				q[++tail].h=x1;
				q[tail].l=y1;
				a[x1][y1].visi=0;
				a[x1][y1].cs=tail;
			}
		}
	}
	for (int i=1;i<=l;i++){
		for (int j=1;j<=h;j++){
			if (a[i][j].visi)
				cout<<-1;
			else
				cout<<a[i][j].cs<<'\n';
		}
	}
	
	
	return 0;
}
2024/11/23 16:23
加载中...