@[seven7777](/user/325650)
```cpp
5
0 0 0 0 0
0 1 1 1 1
0 1 0 0 1
0 1 0 1 1
0 1 1 1 0
```
by w20230071_QwQ @ 2021-03-28 18:29:52
cnmd
by 深雨shenyu @ 2021-03-28 18:54:52
@[w20230071_QwQ](/user/499994) 那要怎么改呢
by seven7777 @ 2021-03-28 20:24:10
@[seven7777](/user/325650)
```cpp
#include <bits/stdc++.h>
using namespace std;
int a[100][100]={0},b[100][100]={0}; //数组用来记录原来的数
int n;
int dx[5]={0,-1,0,0,1};
int dy[5]={0,0,-1,1,0};
void dfs(int x,int y)
{
if(a[x][y]!=0)return ;//**//
a[x][y]=1;//**//
for(int i=1;i<5;i++)
{
int nx=x+dx[i],ny=y+dy[i];
if(nx>=1&&nx<=n&&ny>=1&&ny<=n&&a[nx][ny]==0)
{//**//
dfs(nx,ny);
}
}
return;
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
cin>>b[i][j];
if(b[i][j]==0)
a[i][j]=0;
else
a[i][j]=2;
}
}
for(int i=1;i<=n;i++) //****//
dfs(i,1),dfs(1,i),dfs(i,n),dfs(n,i);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(a[i][j]==1)
cout<<0<<" ";
if(a[i][j]==2)
cout<<1<<" ";
if(a[i][j]==0)
cout<<2<<" ";
}
cout<<endl;
}
return 0;
}
```
by w20230071_QwQ @ 2021-03-28 20:46:05
@[w20230071_QwQ](/user/499994) 明白了,谢谢
by seven7777 @ 2021-03-28 21:00:53