求大佬,全mle,蒟蒻一只,不知何调。

P1162 填涂颜色

dage88888888 @ 2024-03-22 19:18:57

#include<bits/stdc++.h>
#define maxn 186
#define ll long long
using namespace std;
ll n;
ll a[maxn][maxn];
int walk1[5]={0,-1,1,0,0},walk2[5]={0,0,0,-1,1};
void dfs(int x,int y)
{
    if(x<0||x>n+1||y<0||y>n+1||a[x][y]==1) return ;
    a[x][y]=0;
    for(int i=1;i<=4;i++)
    {
        dfs(x+walk1[i],y+walk2[i]);
    }
}
int main()
{
    scanf("%ld",&n);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            scanf("%ld",&a[i][j]);
            if(a[i][j]==0) a[i][j]=2;
        }
    }
    dfs(0,0);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=n;j++)
        {
            cout<<a[i][j]<<" ";
        }
        cout<<endl;
    }
    return 0;
}

by zhangbonan1121 @ 2024-03-22 19:29:54

哪题啊


by Bismuth_Sulfate @ 2024-03-22 19:53:31

@zhangbonan1121 您不看右边所属板块和关联题目的吗


|