BBY123 @ 2023-11-16 17:13:26
#include<bits/stdc++.h>
using namespace std;
int n,m,tx[5]={0,1,-1,0,0},ty[5]={0,0,0,1,-1},ans;
bool v[101][101],k[101][101];
char q[101][101];
void dfs(int x,int y){
if(x>n+1||y>m+1||x<0||y<0||q[x][y]=='1') return;
q[x][y]='1';
k[x][y]=1;
for(int i = 1;i <= 4;i++){
dfs(x+tx[i],y+ty[i]);
}
}
int main(){
cin>>n;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
cin>>q[i][j];
if(q[i][j]=='1') v[i][j]=1;
}
}
dfs(0,0);
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(q[i][j]=='0'&&!k[i][j]){
q[i][j]='2';
}
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
if(q[i][j]=='1'&&!v[i][j]){
q[i][j]='0';
}
}
}
for(int i = 1;i <= n;i++){
for(int j = 1;j <= n;j++){
cout<<q[i][j]<<" ";
}
cout<<endl;
}
return 0;
}
by Genius_physicist @ 2024-01-30 10:59:29
你看奥特曼??