AcWing 1113. 红与黑
原题链接
简单
作者:
喜欢日奈大可爱
,
2024-04-07 21:24:54
,
所有人可见
,
阅读 1
python3 dfs
def dfs(i, j):
res = 1
g[i][j] = '#'
for k in range(4):
x = i + dx[k]
y = j + dy[k]
if (x >= 0)and(x < h)and(y >= 0)and(y < w)and g[x][y] == '.':
res += dfs(x, y)
return res
while(True):
w, h = map(int, input().split())
if w == 0 and h == 0:
break
g = []
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]
for i in range(h):
a = input().strip()
g.append([i for i in a])
for i in range(h):
for j in range(w):
if g[i][j] == '@':
print(dfs(i, j))