求助
查看原帖
求助
1436449
ding20120116楼主2025/2/7 15:37

RE了,Why?

#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=200;
struct node{int x,y,bu;};
queue<node> q;
int n,m,a[N][N],mk[N][N],ans[N][N];
int xy[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
char s;
void bfs(){
	while(!q.empty()){
		node x=q.front();
		q.pop();
		ans[x.x][x.y]=x.bu;
		for(int i=0;i<4;i++){
			int xx=x.x+xy[i][0],yy=x.y+xy[i][1];
			if(xx>n||yy>m||mk[xx][yy]||a[xx][yy]) continue;
			mk[xx][yy]=1;
			q.push((node){xx,yy,x.bu+1});
			
		}
	}
}
signed main(){
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>s;
			a[i][j]=s-'0';
			if(a[i][j]==1){
				q.push((node){i,j,0});
				mk[i][j]=1;
			}
		}
	}
	bfs();
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++) cout<<ans[i][j]<<" ";
		cout<<"\n";
	} 
	return 0;
}

求助

2025/2/7 15:37
加载中...