문제 링크
https://www.acmicpc.net/problem/2110
문제
입력 조건
출력 조건
입력 예시1
출력 예시1
입력 예시2
출력 예시2
풀이 전 생각
예제 코드
def binarysearch(start,end,c):
while start<=end:
mid = (start+end)//2
current = arr[0]
count = 1
for i in range(1,len(arr)):
if arr[i]>=current+mid:
count+=1
current=arr[i]
if count < c:
end = mid - 1
elif count >= c:
answer = mid
start = mid + 1
print(answer)
n,c = map(int,input().split())
arr = []
for _ in range(n):
arr.append(int(input()))
arr.sort()
start = 1
end = arr[-1]-arr[0]
binarysearch(start,end,c)
생각
upper bound
https://www.acmicpc.net/blog/view/109
parametric search
https://ialy1595.github.io/post/parametric-search/
파라매트릭 서치 (Parametric Search) | ialy's blog
24 Jul 2020, 17:53 파라매트릭 서치 (Parametric Search)
ialy1595.github.io
'알고리즘 > 24-25 겨울 코딩테스트 스터디' 카테고리의 다른 글
백준 10815번 - 숫자 카드 - 파이썬(Python) (0) | 2025.02.16 |
---|---|
백준 1642번 - 랜선 자르기 - 파이썬(Python) (0) | 2025.02.16 |
백준 10816번 - 숫자 카드 2 - 파이썬(Python) (0) | 2025.02.13 |
백준 7576번 - 토마토 - 파이썬(Python) (0) | 2025.02.12 |
백준 7562번 - 나이트의 이동 - 파이썬(Python) (0) | 2025.02.11 |