๋ฌธ์
๋ฐฑ์ค ์จ๋ผ์ธ ์ ์ง - 6186๋ฒ
ํ์ด ๊ณผ์
์ธ์ ํ ์๋ ๋ญ์น์ ๊ฐ์๋ฅผ ์ฐพ๋ ๋ฌธ์ ์ ๋๋ค.
์๋ ๋ญ์น๋ ์๋ก ์ธ์ ํ์ง ์๊ธฐ ๋๋ฌธ์ ๊ฐ ์ขํ๋ฅผ ์ํํ๋ฉด์ ์๋๊ฐ ๋ฐ๊ฒฌ๋๋ฉด ์ธ์ ํ ๋ค ๋ฐฉํฅ์ ๋ชจ๋
๋ฐฉ๋ฌธํด๋ณด๋ ๋ฐฉ๋ฒ์ผ๋ก ๋ชจ๋ ์๋ ๋ญ์น๋ฅผ ํ์ํ ์ ์์ต๋๋ค.
์ฝ๋
import sys
R, C = list(map(int, sys.stdin.readline().split()))
grass = [list(sys.stdin.readline().strip()) for _ in range(R)]
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]
def solution():
clump = 0
visit = [[0] * C for _ in range(R)]
for r in range(R):
for c in range(C):
if not visit[r][c] and grass[r][c] == '#':
visit[r][c] = 1
clump += 1
for i in range(4):
nr, nc = r + dx[i], c + dy[i]
if 0 <= nr < R and 0 <= nc < C:
if not visit[nr][nc]:
visit[nr][nc] = 1
return clump
print(solution())
๋ฐ์ํ
'๐ algorithm > boj' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
BOJ 18111 - ๋ง์ธํฌ๋ํํธ (0) | 2021.03.08 |
---|---|
BOJ 1806 - ๋ถ๋ถํฉ (0) | 2021.03.08 |
BOJ 8972 - ๋ฏธ์น ์๋์ด๋ ธ (0) | 2021.03.08 |
BOJ 19941 - ํ๋ฒ๊ฑฐ ๋ถ๋ฐฐ (0) | 2021.03.08 |
BOJ 16469 - ์๋ ์ ํ (0) | 2021.03.05 |
๐ฌ ๋๊ธ