[20251003] PGM / Lv3 / 주사위 고르기 / 이강현 #1030
Merged
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.
🧷 문제 링크
https://school.programmers.co.kr/learn/courses/30/lessons/258709
🧭 풀이 시간
60분
👀 체감 난이도
✏️ 문제 설명
주사위 n개 중 n/2개를 고른 후 A와 B가 나눠가짐.
그리고 하나씩 굴려서 총합으로 승패를 가릴때, A는 가장 승리 확률이 높은 주사위를 뽑고 싶음.
그때 주사위 조합을 출력.
🔍 풀이 방법
백트래킹, 이분탐색
백트래킹으로 A와 B가 주사위를 나눠가지고
그렇게 생성된 조합을 통해 A와 B 각각 주사위 합을 따로 리스트에 저장해둠.
B의 리스트를 정렬한 후 이분탐색으로 A의 값보다 작은 경우의 개수를 얻음. 이것이 A의 현재 조합의 주사위 눈에서의 승리 개수임.
이를 모든 주사위 눈의 경우에서 진행하고 모두 더하면 A의 현재 주사위 조합에서의 승리 개수를 얻음.
이 승리 개수가 가장 큰 조합을 출력함.
⏳ 회고
주사위의 조합이 정해졌을때, 이 조합에서 나올 수 있는 눈에서 합을 구해내는 과정이 너무 헷갈렸다.