0分求助

P1162 填涂颜色

输出时1字框中的2都是0
by Sci_8633 @ 2024-07-13 17:34:13


题号说一下,Please
by wby_1234 @ 2024-07-13 17:56:58


dfs的AC代码可以参考一下: ```c #include<bits/stdc++.h> using namespace std; int dx[4]={0,0,1,-1},dy[4]={1,-1,0,0},n,s; int a[31][31]; void dfs(int x,int y) { if(x<1||y<1||x>n||y>n||a[x][y]!=0)return; a[x][y]=3; for(int i=0;i<4;i++)dfs(x+dx[i],y+dy[i]); } 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=1;i<=n;i++)dfs(1,i); for(int i=1;i<=n;i++)dfs(i,n); for(int i=1;i<=n;i++)dfs(i,1); for(int i=1;i<=n;i++)dfs(n,i); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(a[i][j]==3)cout<<"0 "; if(a[i][j]==1)cout<<"1 "; if(a[i][j]==0)cout<<"2 "; } cout<<"\n"; } return 0; } ``` (求关 QWQ
by wuzhitong @ 2024-07-18 18:52:07


|