-
백준 1206 python백준/이분 탐색 2023. 4. 3. 14:56
문제
https://www.acmicpc.net/problem/1206
풀이
- 출력값의 최댓값은 1000이다.
- 1~1000까지 o를 증가시키면서 check 조건을 만족하면 루프를 종료시킨다.
- 이분 탐색을 이용해 탐색 시간을 줄인다.
import math N=int(input()) I,o=[float(input()) for _ in range(N)],0 def check(o): for x in I: l,r=0,10*o while l<r: mid=math.floor((l+r)/2) if (mid/o)<x: l=mid+1 else: r=mid if math.trunc((l/o)*1000)/1000!=x: return False return True while o < 1000: o+=1 if check(o): break print(o)
참조
https://codingpracticing.tistory.com/425
'백준 > 이분 탐색' 카테고리의 다른 글
백준 1166 python (2) 2023.03.13 백준 1715 nodejs (0) 2023.01.09 백준 1300 nodejs (0) 2023.01.01