为什么无法运行啊??
  • 板块P1443 马的遍历
  • 楼主dbw81
  • 当前回复4
  • 已保存回复4
  • 发布时间2024/1/28 18:30
  • 上次更新2024/1/28 20:33:28
查看原帖
为什么无法运行啊??
1129296
dbw81楼主2024/1/28 18:30
#include<bits/stdc++.h>
using namespace std;
int dir[8][2]={{1,2},{1,-2},{-1,2},{-1,-2},{2,1},{2,-1},{-2,1},{-2,-1}};
struct aa{
	int x,y;
};
int ans[454][454];
queue<aa> q;
int n;
int m;
int x;
int y;
int mian(){
	cin>>n>>m>>x>>y;
	aa xx={x,y};
	q.push(xx);
	memset (ans,-1,sizeof(ans));
	ans[x][y]=0;
	while(!q.empty()){
		aa topp=q.front();
		q.pop();
		int ax=topp.x;
		int ay=topp.y;
		for(int i=0;i<8;++i){
			int bx=ax+dir[i][0];
			int by=ay+dir[i][0];
			if(by>m||ans[bx][by]!=-1||by<1||bx<1||bx>n){
				 continue;
			}
		   ans[bx][by]=ans[ax][ay]+1;
		aa cur={bx,by};
		q.push(cur);
		}
	}
	for(int i=1;i<=n;++i){
		for(int j=1;j<=m;++j){
			cout<<ans[i][j]<<"     ";
		}
		cout<<endl;
	}
	return 0;
}




2024/1/28 18:30
加载中...