이코테_ch3 greedy python

2023. 3. 19. 14:24카테고리 없음

728x90

오늘은 sqld 자격증 시험을 보고 온 날이다.

좀 더 파이썬 다운 코드를 짜보는 연습을 하겠어 ! ><

 

[part2]

숫자 카드 게임 

n, m = map(int, input().split())
result = 0

for _ in range(n):
    card = list(map(int, input().split()))
    min_val = min(card)
    result = max(min_val, result)

print(result)

 

1이 될때까지

n, k = map(int, input().split())

cnt = 0
target = 0

# 25 3
# 25 -1 = 24
# 24/3 = 8
# 8 - 1 = 7
# 7 - 1 = 6
# 6/3 = 2
# 2 - 1 = 1

while True:
    target = (n//k) * k
    cnt += (n - target)
    n = target//k
    cnt += 1

    if n < k:
        cnt += (n-1)
        break


print(cnt)