이코테_Greed

  • 거스름돈
n = 1260
count = 0

coin_types = [500, 100, 50, 10]
for coin in coin_types:
    count += n//coin
    n%=coin
print(count)
6

  • 큰 수의 법칙
a = [5,7,2]
b = [3, 4, 3, 4, 3] 
lim = a[1]
idx_ = a[2]
def solution(a, b):
    lim = a[1]
    idx_ = a[2]
    b.sort(reverse = True)
    sum_ = 0
    n = 1
    for i in range(lim):
        if n<= idx_: 
            sum_+=b[0]
            n+=1
        elif n>idx_:
            sum_+=b[1]
            n=1
    return sum_
solution(a,b)
28
arr = [list(map(int, input().split())) for _ in range(2)]
5 7 2
3 4 3 4 3
solution(arr[0],arr[1])
28

  • 숫자 카드 게임
n, m = map(int, input().split())
2 4
arr = [list(map(int, input().split()))  for _ in range(n)]
7 3 1 8 
3 3 3 4
small = 0
for i in arr:
    if min(i) >= small:
        small = min(i)
3

  • 1이 될 때까지
n, k = map(int, input().split())
25 3
count = 0
while n!=1:
    if n%k==0:
        n/=k
        count+=1
    else:
        n-=1
        count+=1
print(count)
6

Comments