-
선입 선출 스케줄링코딩 테스트/Level 3 2022. 9. 4. 10:29반응형
https://school.programmers.co.kr/learn/courses/30/lessons/12920
파이썬
무지성 코딩.
def solution(n, cores): board = [0 for _ in cores] while True: for i, v in enumerate(cores): if board[i] == 0: n -= 1 board[i] = v if n == 0: return i + 1 for i in range(len(cores)): board[i] -= 1
이분(이진) 탐색
파라메트릭 서치
def solution(n, cores): if n < len(cores): return n n -= len(cores) left, right = 1, max(cores) * n while left < right: mid = (left + right) // 2 works = sum(mid // time for time in cores) if works >= n: right = mid else: left = mid + 1 n -= sum((right - 1) // time for time in cores) for i, time in enumerate(cores): if right % time == 0: n -= 1 if n == 0: return i + 1
반응형