[20260103] BOJ / G4 / 우체국 / 한종욱 #1765
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/2141
🧭 풀이 시간
40분
👀 체감 난이도
✏️ 문제 설명
마을마다 사람들의 인원이 다르다. 이 마을들을 위해 우체국을 세우려고 하는데, 우체국은 각 사람들까지의 거리의 합이 최소가 되는 위치에 우체국을 세우기로 결정하였다. 우체국의 위치는?
🔍 풀이 방법
우체국의 위치는 마을 사람들의 위치의 중앙값이다. 마을들을 위치에 따라 정렬하고, 첫 마을부터 사람 수를 더해 과반수가 넘어가는 지점이 우체국의 위치이다.
과반수를 나타낼 때,
이다. 이를 한 번에 할 수 있는 것은
⏳ 회고
문제를 보자마자, 난민 문제가 생각났다. 그래서 중앙값을 쉽게 알 수 있었는데, 홀짝의 특성을 고려하지 못했다.