acgo题库
  • 首页
  • 题库
  • 学习
  • 天梯
  • 备赛

    竞赛

    • CSP-J/S
    • 蓝桥杯

    考级

    • GESP
    • CPA
    • 电子学会考级
  • 资讯
  • 竞赛
  • 讨论
  • 团队
  • 商城
登录
注册
题目详情提交记录(0)
  • 题解

    #include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int h, w, d; cin >> h >> w >> d; vector<string> g(h); queue<pair<int,int>> q; vector<vector<int>> dist(h, vector<int>(w, -1)); for (int i = 0; i < h; i++) { cin >> g[i]; for (int j = 0; j < w; j++) { if (g[i][j] == 'H') { dist[i][j] = 0; q.push({i, j}); } } } int dr[] = {-1,1,0,0}; int dc[] = {0,0,-1,1}; while (!q.empty()) { auto [r, c] = q.front(); q.pop(); if (dist[r][c] >= d) continue; for (int k = 0; k < 4; k++) { int nr = r + dr[k], nc = c + dc[k]; if (nr < 0 || nr >= h || nc < 0 || nc >= w) continue; if (g[nr][nc] == '#') continue; if (dist[nr][nc] != -1) continue; dist[nr][nc] = dist[r][c] + 1; q.push({nr, nc}); } } int cnt = 0; for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) if (dist[i][j] != -1) cnt++; cout << cnt << "\n"; return 0; }

    userId_undefined
    未知
    模拟·模拟练习生倔强青铜冒泡宗师→排序元老
    0阅读
    0回复
    0点赞
暂无数据

提交答案之后,这里将显示提交结果~

首页