Week9 서영탁 2617 구슬찾기 풀이 #148
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.
풀이
과제로 했었던 SWEA 키 순서와 비슷한 문제였습니다.
해당 구슬보다 무거운 구슬 단방향 그래프(
heavy)와 가벼운 구슬 단방향 그래프(light)를 사용했습니다.그리고 bfs 방법을 사용하여 단방향 그래프를 탐색하면서 해당 구슬보다 무겁거나, 가벼운 구슬의 개수를 계산하였습니다.
문제에서 구하라는 것은 무게가 중간이 될 수 없는 구슬의 개수인데,
무게가 중간이 될 수 없으려면, 해당 구슬보다 무겁거나, 가벼운 구슬이 전체 구슬 수의 절반을 초과한다면 중간이 될 수 없습니다.
따라서, 해당 구슬의 무겁거나, 가벼운 구슬의 개수가 전체 구슬의 수의 절반을 초과한다면 카운트를 증가시켰습니다.
리뷰 요청 사항