48分?
by 倍镜 @ 2020-07-10 09:56:44
qwq
by 倍镜 @ 2020-07-10 09:56:54
您是怎么做到的QAQ
by 倍镜 @ 2020-07-10 09:57:13
```cpp
可参考
#include<bits/stdc++.h>
using namespace std;
int n,flag[32][32],a[32][32]={0},dir[5][2]={{0,0},{1,0},{0,1},{-1,0},{0,-1}};
void dfs(int x,int y)
{
if(x<0||x>n+1||y<0||y>n+1||flag[x][y]==1) return;
flag[x][y]=1;
for(int i=1;i<=4;i++)
{
dfs(x+dir[i][0],y+dir[i][1]);
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
cin>>a[i][j];
for(int i=0;i<=n+1;i++)
for(int j=0;j<=n+1;j++)
{
flag[i][j]=0;
if(a[i][j]==1) flag[i][j]=1;
}
dfs(0,0);
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(flag[i][j]==0) a[i][j]=2;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}
by s唐家强 @ 2020-07-19 16:20:32