[BOJ] 1012_유기농 배추 / 실버 2 / 90분 / X #274
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
📖 풀이한 문제
⭐️ 문제에서 주로 사용한 알고리즘
BFS
대략적인 코드 설명
1이 인접한 칸들을 연결하여 한 구역이라고 생각하면, 구역마다 지렁이 1마리가 필요하다고 생각할 수 있다.
그래서 처음에 그래프의 각 칸을 돌다가 1인 칸을 발견하면 BFS를 수행한다. BFS를 수행하면 1인 칸은 0으로 변경하게 되므로, 한 구역의 BFS가 모두 끝나면 그 구역은 1이 모두 0으로 바뀐다.
즉, 1인 칸 하나를 발견하여 그 칸에서 BFS를 수행하면 그 구역의 1은 모두 0으로 바뀌므로, 1인 칸을 발견할 때마다 카운트 + 1을 하고 BFS를 수행하면 정답을 구할 수 있다.