We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 68e6258 commit 893f90dCopy full SHA for 893f90d
1 file changed
live8/test85/문제2/박희경.py
@@ -0,0 +1,49 @@
1
+import sys
2
+from collections import *
3
+
4
+input = sys.stdin.readline
5
6
+dx = [-1, 1, 0, 0]
7
+dy = [0, 0, -1, 1]
8
9
10
+def bfs(x, y):
11
+ q = deque([(x, y)])
12
+ while q:
13
+ x, y = q.popleft()
14
+ for i in range(4):
15
+ nx, ny = x + dx[i], y + dy[i]
16
+ if 0 <= nx < h and 0 <= ny < w and grid[nx][ny] == '#':
17
+ grid[nx][ny] = '.'
18
+ q.append((nx, ny))
19
+ return True
20
21
22
+t = int(input())
23
+for _ in range(t):
24
+ h, w = map(int, input().split())
25
+ grid = []
26
+ for _ in range(h):
27
+ grid.append(list(map(str, input().rstrip())))
28
29
+ cnt = 0
30
+ for i in range(h):
31
+ for j in range(w):
32
+ if grid[i][j] == '#':
33
+ if bfs(i, j):
34
+ cnt += 1
35
+ print(cnt)
36
37
38
+"""
39
+2
40
+4 4
41
+#.#.
42
+.#.#
43
+#.##
44
45
+3 5
46
+###.#
47
+..#..
48
+#.###
49
0 commit comments