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.