欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1872A.Two Vessels
Two Vessels
You have two vessels with water. The first vessel contains grams of water, and the second vessel contains grams of water. Both vessels are very large and can hold any amount of water.
You also have an empty cup that can hold up to grams of water.
In one move, you can scoop up to grams of water from any vessel and pour it into the other vessel. Note that the mass of water poured in one move does not have to be an integer.
What is the minimum number of moves required to make the masses of water in the vessels equal? Note that you cannot perform any actions other than the described moves.
Input
Each test contains multiple test cases. The first line contains the number of test cases (). The description of the test cases follows.
Each test case consists of a single line containing three integers , , and () — the mass of water in the vessels and the capacity of the cup, respectively.
Output
For each test case, output a single number — the minimum number of moves required to make the masses of water in the vessels equal. It can be shown, that it is always possible.
Note
In the first test case, only one move is enough: if we pour grams of water from the second vessel into the first one, both vessels will contain grams of water.
In the second example test case, three moves are enough:
- Pour grams of water from the first vessel into the second one. After this move, the first vessel will contain grams of water, and the second vessel will contain grams.
- Pour grams of water from the first vessel into the second one. After this move, the first vessel will contain grams of water, and the second vessel will contain grams.
- Finally, pour grams of water from the first vessel into the second one. After this move, the first vessel will contain grams of water, and the second vessel will contain grams.
Note that this is not the only way to equalize the vessels in moves, but there is no way to do it in moves.
In the third example test case, the vessels initially contain the same amount of water, so no moves are needed. The answer is .
Samples
6
3 7 2
17 4 3
17 17 1
17 21 100
1 100 1
97 4 3
1
3
0
1
50
16
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |