함께하는 데이터 분석

[이것이 코딩테스트다] 이코테 파이썬 그리디 본문

코딩 테스트/이것이 코딩테스트다

[이것이 코딩테스트다] 이코테 파이썬 그리디

JEONGHEON 2023. 7. 13. 20:30

거스름돈

n = int(input())
arr = [500, 100, 50, 10]
count = 0
for i in arr :
    count += n // i
    n %= i
print(count)

 

큰 수의 법칙

N, M, K = map(int, input().split())
data = list(map(int, input().split()))

data.sort()

summ = 0
i = 1
while i <= M :
    if i % (K + 1) == 0 :
        summ += data[N - 2]
    else :
        summ += data[N - 1]
    i += 1
print(summ)

 

숫자 카드 게임

N, M = map(int, input().split())

result = []
for _ in range(N) :
    data = list(map(int, input().split()))
    result.append(min(data))
print(max(result))

 

1이 될 때까지

N, K = map(int, input().split())

result = 0
while True :
    if N % K == 0 :
        N //= K
    else :
        N -= 1
    result += 1
    if N == 1 :
        break
print(result)