-
[백준] 11047번 동전 0(python)Python/BAEKJOON 2022. 3. 26. 17:26728x90
문제)
알고리즘)
그리디 알고리즘 대표적인 문제
-동전을 내림차순으로 정렬
-큰값부터 차례로 나눠준다 (나눌때 몫을 카운트)
동전 수 출력
코드)
#다시 풀이 # 동전0 import sys from collections import deque input = sys.stdin.readline cnt, price = map(int, input().split()) result = 0 coin = [] for _ in range(cnt): coin.append(int(input())) coin.sort(reverse= True) coin = deque(coin) while coin: current = coin.popleft() if current > price: continue result += (price//current) price %= current print(result)
728x90'Python > BAEKJOON' 카테고리의 다른 글
[백준] 21921번 블로그(python) (0) 2023.01.02 [백준] 2667번 단지번호붙이기(python) (0) 2022.06.22 [백준] 1057번 토너먼트(python) (0) 2022.03.26 [백준] 2579번 계단오르기(python) (0) 2022.03.26 [백준] 1012번 유기농 배추(python) (0) 2022.03.16