已知道原来要闭合圈,谢谢
```cpp
#include<cstdio>
#include<cstring>
using namespace std;
bool v[31][31];
int n;
void dfs(int x,int y)
{
if(x>(n+1)||y>(n+1)||x<0||y<0) return ;
if(v[x][y]==false) return ;
else
{
v[x][y]=false;
dfs(x+1,y);
dfs(x,y+1);
dfs(x-1,y);
dfs(x,y-1);
}
}
int a[31][31];
int main()
{
scanf("%d",&n);
memset(a,0,sizeof(a));
memset(v,true,sizeof(v));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
if(a[i][j]==0)v[i][j]=true;
else v[i][j]=false;
}
}
dfs(0,0);dfs(n+1,n+1);dfs(0,n+1);dfs(n+1,0);
for(int i=1;i<=n;i++)
{
for(int j=1;j<n;j++)
{
if(v[i][j]==true)
{
printf("%d ",2);
}
else printf("%d ",a[i][j]);
}
if(v[i][n]==true) printf("%d\n",2);
else printf("%d\n",a[i][n]);
}
return 0;
}
```
by M__HD @ 2017-07-15 14:44:50