救救孩子QWQ 2AC8WA
查看原帖
救救孩子QWQ 2AC8WA
1412841
BaiBaiShaFeng楼主2024/10/3 17:04
#include <bits/stdc++.h>
using namespace std;

int xmove[8]={-1,-2,-2,-1,1,2,2,1};
int ymove[8]={2,1,-1,-2,2,1,-1,-2};

queue <pair<int,int>> que;
int step[455][455]={-1};//这个垃圾东西竟然是存我的步数的 !!! 
bool visited[455][455]={false};//这个废物东西竟然是存是否访问过的!!! 

int main(){
	int n, m, x, y;
	memset(step, -1, sizeof(step));
	memset(visited, false, sizeof(visited));
	cin>>n>>m>>x>>y;
	step[x][y]=0;//开始站的垃圾地方 !!! 
	visited[x][y]=true;
	que.push(make_pair(x,y));
	while (!que.empty()){//混蛋队列不是空的 才行!!!!! 
		int stx=que.front().first;
		int sty=que.front().second;//开始的两个鬼东西!!!!! 
		que.pop();//初始位置鬼!!! 
		for (int i=0; i<8; i++){//对应八个方向!!!!! 
			int later_x=stx+xmove[i];//建立走的x!!!! 
			int later_y=sty+ymove[i];//给老子开始动 !!!
			if(later_x<1 || later_x>n || later_y<1 || later_y>m || visited[later_x][later_y]==true){
				continue;//判断两个傻缺坐标是不是在1到限制的垃圾范围内!!!!! 
			} //往下绝对就在了!!!!!!! 
			visited[later_x][later_y]=true;
			que.push(make_pair(later_x,later_y));
			step[later_x][later_y]=step[stx][sty]+1;
		}
	} 
	for(int i=1; i<=m; i++){
		for(int j=1; j<=n; j++){
			cout<<step[j][i]<<" ";
		}
		cout<<endl;
	}
	return 0;
}
2024/10/3 17:04
加载中...