求助#6 WA了,有大佬看看嘛

P1162 填涂颜色

```cpp #include<iostream> #include<cstdio> #include<cstring> using namespace std; int f[33][33]; int x,y,i,j,n; bool flag[33][33]; int dx[5]={0,1,0,-1,0},dy[5]={0,0,1,0,-1}; void work(int i,int j){ if(f[i][j]==1||flag[i][j]==1||i==n+1||i==-1||j==-1||j==n+1)return; int a; flag[i][j]=1; for(a=1;a<=4;a++)work(i+dx[a],j+dy[a]); return; } int main(){ memset(flag,0,sizeof flag); scanf("%d",&n); for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ scanf("%d",&f[i][j]); if(f[i][j])flag[i][j]=1; } } for(i=1;i<=n;i++){ work(i,1); work(1,i); work(n,i); work(i,n); } for(i=1;i<=n;i++){ for(j=1;j<=n;j++){ if(flag[i][j]) printf("%d ",f[i][j]); else printf("2 "); } printf("\n"); } return 0; } AC代码(求关注)
by LEZ2012 @ 2023-04-09 21:00:49


|