- 2025西门春学期第7-10次课0318.20
天然气开采
- 2025-3-25 17:33:13 @
from collections import deque
h, w = map(int, input().split()) grid = [] for _ in range(h): line = input().strip() grid.append(list(line))
visited = [[False for _ in range(w)] for _ in range(h)] count = 0 directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for i in range(h): for j in range(w): if grid[i][j] == 'Y' and not visited[i][j]: queue = deque() queue.append((i, j)) visited[i][j] = True while queue: x, y = queue.popleft() for dx, dy in directions: nx = x + dx ny = y + dy if 0 <= nx < h and 0 <= ny < w: if grid[nx][ny] == 'Y' and not visited[nx][ny]: visited[nx][ny] = True queue.append((nx, ny)) count += 1
print(count)
2 条评论
-
xm2023007 传奇王者 @ 2025-4-19 11:20:38
你好无聊
-
2025-3-25 17:35:19@
此代码为python
- 1