5 条题解

  • 0
    @ 2025-3-22 16:07:56

    #include<bits/stdc++.h>//导入输出工具库 using namespace std;//规定一个范围空间 叫std

    int n , m , d , e , cnt; char a[1005][1005]; bool vis[1005][1005]; struct node{ int x, y; };

    bool chicken(int x , int y){ if(x >= 1 && x <= n && y >= 1 && y <= m && a[x][y] == '.') return 1; else return 0; } node dxy[4] = {{1 , 0} , {0 , 1} , {-1 , 0} , {0 , -1}};

    int bfs(int x , int y){; queue q; node t1; t1.x = x; t1.y = y; vis[t1.x ][t1.y ] = '#'; q.push(t1); cnt++; while(!q.empty()){ node t2 = q.front(); q.pop(); for(int i = 0;i < 4;i++){ node t3; t3.x = t2.x + dxy[i].x ; t3.y = t2.y + dxy[i].y ; if(chicken(t3.x , t3.y )){ a[t3.x ][t3.y ] = '#'; q.push(t3); cnt++; } }

    }
    return cnt;
    

    } int main()//主程序的入口 { cin >> m >> n; for(int i = 1;i <= n;i++){ for(int j = 1;j <= m;j++){ cin >> a[i][j]; if(a[i][j] == '@'){ d = i; e = j; } } } cout << bfs(d , e); return 0; }

    信息

    ID
    3004
    时间
    1000ms
    内存
    256MiB
    难度
    3
    标签
    递交数
    446
    已通过
    104
    上传者