2 solutions

  • 1
    @ 2024-7-11 14:46:59
    #include<bits/stdc++.h>
    using namespace std;
    const int N=15;
    typedef pair<int,int> PII;
    #define x first
    #define y second
    int dx[]={-1,1,0,0};
    int dy[]={0,0,-1,1};
    int n=10,m=10;
    char g[N][N];
    bool st[N][N];
    void bfs(int x,int y)
    {
       queue<PII> q;
       q.push({x,y});
       while(q.size())
       {
          PII t=q.front();
          q.pop();
          for(int i=0;i<4;i++)
          {
             int a=t.x+dx[i],b=t.y+dy[i];
             if(a<0||a>n||b<0||b>m)
             {
                continue;
             }
             if(g[a][b]=='1')
             {
                continue;
             }
             if(st[a][b])
             {
                continue;
             }
             st[a][b]=1;
             q.push({a,b});
          }
       }
    }
    int main()
    {
       for(int i=1;i<=n;i++)
       {
          for(int j=1;j<=m;j++)
          {
             cin>>g[i][j];
          }
       }
       for(int i=1;i<=n;i++)
       {
          for(int j=1;j<=m;j++)
          {
             if((i==1||j==1||i==n||j==m)&&g[i][j]=='0')
             {
                st[i][j]=1;
                bfs(i,j);
             }
          }
       }
       int ans=0;
       for(int i=1;i<=n;i++)
       {
          for(int j=1;j<=m;j++)
          {
             if(st[i][j]==0&&g[i][j]=='0')
             {
                ans++;
             }
          }
       }
       cout<<ans;
       return 0;
    }
    
    • -1
      @ 2024-8-17 14:52:30
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      0 0 0 0 0 0 0 0 0 0
      1 1 1 1 1 1 1 1 1 1
      0 0 0 0 0 0 1 0 0 1
      0 0 0 0 0 0 1 1 0 1
      0 0 0 0 0 0 0 0 1 1
      
      • @ 2025-1-21 11:20:36

        ???

      • @ 2025-1-21 11:21:33

        @ ???

      • @ 2025-1-21 11:22:01

        @ ????????????

    • 1

    Information

    ID
    1006
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    5
    Tags
    (None)
    # Submissions
    51
    Accepted
    13
    Uploaded By