https://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
| ๋ฌธ์ ๋ด์ฉ
| ํ์ด
import sys
input = sys.stdin.readline
# c, m ๋ฐฐ์ด ๋ฐ๊ธฐ
c, m = [0 for i in range(3)], [0 for i in range(3)]
for i in range(3):
c[i], m[i] = map(int, input().split())
# ํ์ฌ ์ธ๋ฑ์ค ๋ฐํฌ๋ฅผ ๋ค์ ์ธ๋ฑ์ค%3 ๋ณ์ ๋ฐํฌ๋ก ์ฎ๊ธธ์ ์๋ ์ต๋์น ์ฎ๊ธฐ๊ธฐ(ํ์ฌ ๋ณ, ๋ค์ ๋ณ ๋ฐํฌ๊ฐ ๊ฐฑ์ )
for i in range(100):
idx = i % 3
next_idx = (idx + 1) % 3
# ๋จ๊ธธ ์, ๋๊ธธ ์ ๊ตฌํ๊ธฐ
possible_v = m[idx] + m[next_idx]
remain_v, next_v = (0, possible_v) if possible_v <= c[next_idx] else (possible_v - c[next_idx], c[next_idx])
# ๊ฐฑ์
m[idx], m[next_idx] = remain_v, next_v
for num in m:
print(num)
์ข ๋ ๊น๋ํ ์ฝ๋
import sys
input = sys.stdin.readline
# c, m ๋ฐฐ์ด ๋ฐ๊ธฐ
c, m = [0 for i in range(3)], [0 for i in range(3)]
for i in range(3):
c[i], m[i] = map(int, input().split())
# ํ์ฌ ์ธ๋ฑ์ค ๋ฐํฌ๋ฅผ ๋ค์ ์ธ๋ฑ์ค%3 ๋ณ์ ๋ฐํฌ๋ก ์ฎ๊ธธ์ ์๋ ์ต๋์น ์ฎ๊ธฐ๊ธฐ(ํ์ฌ ๋ณ, ๋ค์ ๋ณ ๋ฐํฌ๊ฐ ๊ฐฑ์ )
for i in range(100):
idx = i % 3
next_idx = (idx + 1) % 3
# ํ์ฌ, ๋ค์ ๋ณ ์ฐ์ ๋ ๊ฐฑ์
m[idx], m[next_idx] = max(m[idx] - (c[next_idx] - m[next_idx]), 0), min(c[next_idx], m[idx] + m[next_idx])
for num in m:
print(num)
'์๊ณ ๋ฆฌ์ฆ > ๋ฌธ์ ํ์ด' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Python] ๋ฐฑ์ค 14502๋ฒ ์ฐ๊ตฌ์ (0) | 2024.03.17 |
---|---|
[Python] ๋ฐฑ์ค 16768๋ฒ Mooyo Mooyo (1) | 2024.03.06 |
[Python] ๋ฐฑ์ค 9037๋ฒ The candy war (0) | 2024.01.22 |
[Python] ๋ฐฑ์ค 2110๋ฒ ๊ณต์ ๊ธฐ ์ค์น (2) | 2023.10.22 |
[Python] ๋ฐฑ์ค 1236๋ฒ ์ฑ ์งํค๊ธฐ (1) | 2023.10.15 |