1 条题解

  • 0
    @ 2025-4-25 16:54:38
    #include<bits/stdc++.h>
    using namespace std;
    int n, m;
    bool vis[1005][1005];
    string maze[1005];
    int ans, cnt;
    int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    bool in(int x, int y) {
    return x >= 0 && x < n && y >= 0 && y < m;
    }
    void dfs(int x, int y) {
    cnt++;
    vis[x][y] = true;
    for (int i = 0; i < 4; i++) {
    int newX = x + dir[i][0];
    int newY = y + dir[i][1];
    if (in(newX, newY) && maze[newX][newY] == '#' &&!vis[newX][newY]) {
    dfs(newX, newY);
    }
    }
    }
    int main() {
    freopen("cake.in","r",stdin);
    freopen("cake.out","w",stdout);
    cin>>n>>m;
    for(int i=0;i>maze[i];
    }
    for(int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
    if (maze[i][j] == '#' &&!vis[i][j]) {
    cnt = 0;
    dfs(i, j);
    ans = max(ans, cnt);
    }
    }
    }
    cout << ans << endl;
    return 0;
    }
    
    • 1

    信息

    ID
    438
    时间
    1000ms
    内存
    256MiB
    难度
    5
    标签
    (无)
    递交数
    98
    已通过
    39
    上传者