티스토리 뷰

www.acmicpc.net/problem/16769

 

16769번: Mixing Milk

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$. The second and t

www.acmicpc.net

modular 연산은 정말 최고야

 

bucket = [0]*3
amount = [0]*3
for i in range(3):
    bucket[i], amount[i] = map(int, input().split())

for i in range(100):
    howmany = min(amount[i%3], bucket[(i+1)%3]-amount[(i+1)%3])
    amount[i%3] -= howmany
    amount[(i+1)%3] += howmany

for a in amount:
    print(a)

 

bucket = [0]*3
amount = [0]*3

for i in range(3):
    bucket[i], amount[i] = map(int, input().split())

for i in range(100):
    idx = i % 3
    nxt = (idx+1) % 3
    # 동시에 초기화 안해주면, 
    # amount[idx]의 변경된 값 기준으로 amount[nxt]가 계산된다!!
    amount[idx], amount[nxt] = max(amount[idx] - (bucket[nxt] - amount[nxt]), 0), min(bucket[nxt], amount[nxt] + amount[idx])

for a in amount:
    print(a)
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함