XingChen_MoNian @ 2024-02-06 08:46:06
样例没过,找不出来了,求助
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
int n,a[50][50],X[4]={1,-1,0,0},Y[4]={0,0,1,-1},tmp[50][50];
void dfs(int x,int y){
for(int i=0;i<4;i++){
int idx=x+X[i],idy=y+Y[i];
if(idx<1 || idy<1 || idx>n || idy>n || tmp[idx][idy] || a[idx][idy]==1) continue;
tmp[idx][idy]=1;
dfs(idx,idy);
}
return ;
}
int main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
cin>>a[i][j];
}
}
dfs(0,0);
for(int i=1;i<=n;i++){
for(int j=1;j<=n;j++){
if(tmp[i][j]==0 && a[i][j]==0){
a[i][j]=2;
}
cout<<a[i][j]<<" ";
}
cout<<endl;
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
by XingChen_MoNian @ 2024-02-06 08:49:28
找到问题了,边界找错了