QOJ.ac

QOJ

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

#21054. 牛乳を混ぜる

Statistics

農業は競争の激しい仕事で、特に牛乳生産はそうです。Farmer John は生産方法を革新しなければ乳製品事業が打ち負かされると思っています!

幸い、良い考えがあります。自慢の乳牛 Bessie、Elsie、Mildred の牛乳は少しずつ味が違うので、混ぜて完璧な風味にするつもりです。

3頭の牛乳が入った3つのバケツを用意します。容量は異なるかもしれず、満杯とは限りません。バケツ $1$ から $2$、$2$ から $3$、$3$ から $1$、また $1$ から $2$ と循環して、合計100回注ぎます(100回目は $1$ から $2$)。$a$ から $b$ に注ぐときは、$a$ が空になるか $b$ が満杯になるまで、できるだけ多く注ぎます。

100回すべてが終わった後の各バケツの牛乳量を求めてください。

入力

最初の行は空白区切りの整数2つで、最初のバケツの容量 $c_1$ と牛乳量 $m_1$ です。両方とも正で $10^9$ 以下、$c_1 \geq m_1$ です。2、3行目も同様に2、3番目の容量と牛乳量を与えます。

出力

100回注いだ後の各バケツの牛乳量を3行で出力してください。

入出力例

入力 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
(最後の3つの状態が以後循環します……)

問題作成: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.