QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21054. 混合牛奶

Statistics

農業競爭激烈,產奶尤其如此。Farmer John 認為,若不創新產奶方式,他的乳品生意可能慘敗!

幸好他有個好主意。他的三頭冠軍乳牛 Bessie、Elsie、Mildred 產出的牛奶味道略有不同,他計畫混合它們,獲得完美風味。

他拿來裝有三頭牛牛奶的三個桶。桶容量可能不同,也可能未滿。他先將桶 $1$ 倒入桶 $2$,再將桶 $2$ 倒入桶 $3$,然後桶 $3$ 倒入桶 $1$,接著桶 $1$ 倒入桶 $2$,如此循環共 100 次(第 100 次是桶 $1$ 倒入桶 $2$)。從桶 $a$ 倒入桶 $b$ 時,儘可能多倒,直到桶 $a$ 空或桶 $b$ 滿。

請告訴他完成全部 100 次後,每個桶中有多少牛奶。

輸入格式

第一行包含兩個空格分隔的整數:第一個桶的容量 $c_1$ 和牛奶量 $m_1$。兩者均為正且不超過 $10^9$,滿足 $c_1 \geq m_1$。第二、三行類似,包含第二、三個桶的容量與牛奶量。

輸出格式

輸出三行,給出 100 次倒入後每個桶的最終牛奶量。

範例

輸入格式 1

10 3
11 4
12 5

輸出格式 1

0
10
2

說明

本例中,倒入過程中各桶的牛奶量如下:

初始狀態: 3  4  5
1. 倒入 1->2:  0  7  5
2. 倒入 2->3:  0  0  12
3. 倒入 3->1:  10 0  2
4. 倒入 1->2:  0  10 2
5. 倒入 2->3:  0  0  12
(最後三個狀態隨後循環重複……)

題目作者:Brian Dean

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.