어읽로꾸거
BOJ 6186 Best Grass 본문
백준 6186 링크
https://www.acmicpc.net/problem/6186
풀이
🙄
코드
from collections import deque
def dajik():
q=deque([(i,j)])
while q:
y,x=q.popleft()
for k in range(4):
ny,nx=y+ly[k],x+lx[k]
if 0<=ny<n and 0<=nx<m and mp[ny][nx]=='#' and visit[ny][nx]==0:
visit[ny][nx]=1
q.append((ny,nx))
n,m=map(int,input().split())
mp=[input() for _ in range(n)]
visit=[[0]*m for _ in range(n)]
ly,lx=[0,0,-1,1],[1,-1,0,0]
count=0
for i in range(n):
for j in range(m):
if mp[i][j]=='#' and visit[i][j]==0:
visit[i][j]=1
dajik()
count=count+1
print(count)
'알고리즘' 카테고리의 다른 글
BOJ 1038 감소하는 수 (0) | 2019.09.15 |
---|---|
BOJ 17141 연구소 2 (0) | 2019.09.13 |
BOJ 13549 숨바꼭질3 (0) | 2019.04.22 |
BOJ 6118 숨바꼭질 (0) | 2019.04.19 |
BOJ 6087 레이저 통신 (0) | 2019.04.18 |