[20251021] BOJ / P5 / 카드 게임 / 한종욱 #1181
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://www.acmicpc.net/problem/16566
🧭 풀이 시간
45분
👀 체감 난이도
✏️ 문제 설명
제시된 카드보다 큰 값 중 제일 작은 값을 제시하라.
🔍 풀이 방법
이분탐색을 통해 제시된 카드 중 제일 큰 값의 인덱스를 찾고,
used[]배열을 사용해 찾은 인덱스부터 M-1까지 탐색해 사용되지 않은 카드를 찾아서 출력분리집합을 통해, 사용한 카드는 다음 사용 가능한 카드로 연결한다. 이분탐색을 통해 제일 큰 값의 인덱스를 찾고 해당 카드와 연결된 사용할 수 있는 카드를
find()함수로 찾아서 출력⏳ 회고
Union은 일반적으로 양방향 연결인데, 이 문제에선 일방향 연결이 필요했다. 따라서,
uf[x] = y’x를 사용했으니 다음엔 y로 가라’가 맞다. 이분 탐색을 너무 오랜만에 해서, 헷갈렸다.result가 필수가 아니라left를 반환하는 것만으로도 충분했다.