[백준/파이썬] 16769번 풀이

업데이트:



문제 정보


풀이

문제

Farming is competitive business – particularly milk production. Farmer John figures that if he doesn’t innovate in his milk production methods, his dairy business could get creamed!

Fortunately, Farmer John has a good idea. His three prize dairy cows Bessie, Elsie, and Mildred each produce milk with a slightly different taste, and he plans to mix these together to get the perfect blend of flavors.

To mix the three different milks, he takes three buckets containing milk from the three cows. …

입력 요약
The first line of the input file contains two space-separated integers: the capacity $c_1$ of the first bucket, and the amount of milk $m_1$ in the first bucket. Both $c_1$ and $m_1$ are positive and at most 1 billion, with $c_1 \geq m_1$. …

출력 요약
Please print three lines of output, giving the final amount of milk in each bucket, after 100 pour operations.

코드

import sys;read=sys.stdin.readline
l=[list(map(int,read().split()))for _ in range(3)]
for i in range(100):
    s,d=i%3,(i+1)%3
    l[d][1]+=l[s][1]
    t=max(l[d][1]-l[d][0],0)
    l[d][1]-=t
    l[s][1]=t
print('\n'.join(map(lambda x:str(x[1]),l)))

설명

핵심은 구현 관점에서 Farming is competitive business – particularly milk production. Farmer John figures that if he doesn’t innovate in his milk production methods, his d …를 만족하도록 로직을 구성하는 것입니다.

코드는 입력을 파싱한 뒤 조건 분기와 계산을 순서대로 수행하고, 문제에서 요구한 형식으로 결과를 출력합니다.

경계값과 예외 케이스도 함께 고려해 오답이 나기 쉬운 상황을 방지합니다.



다음 읽을거리

관련 허브 페이지에서 같은 주제의 글을 이어서 확인할 수 있습니다.

댓글남기기