CF1872A.Two Vessels
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You have two vessels with water. The first vessel contains a grams of water, and the second vessel contains b 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 c grams of water.
In one move, you can scoop up to c 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.
你有两个装有水的容器。第一个容器中有 a 克水,第二个容器中有 b 克水。两个容器都很大,可以容纳任意量的水。
你还拥有一个空杯子,其最大容量为 c 克水。
在一次操作中,你可以从任一容器中舀取最多 c 克水,并将其倒入另一容器中。注意:单次操作中倒出的水量不必为整数。
请问,使两个容器中水的质量相等所需的最少操作次数是多少?注意:除上述操作外,不允许执行其他任何操作。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). The description of the test cases follows.
Each test case consists of a single line containing three integers a, b, and c (1≤a,b,c≤100) — the mass of water in the vessels and the capacity of the cup, respectively.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是测试用例的描述。
每个测试用例由一行组成,包含三个整数 a、b 和 c(1≤a,b,c≤100)——分别表示容器中水的质量以及杯子的容量。
输出格式
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.
对于每个测试用例,输出一个整数——使各容器中水的质量相等所需的最少移动次数。可以证明,这总是可行的。
输入输出样例
输入#1
6 3 7 2 17 4 3 17 17 1 17 21 100 1 100 1 97 4 3
输出#1
1 3 0 1 50 16
说明/提示
In the first test case, only one move is enough: if we pour 2 grams of water from the second vessel into the first one, both vessels will contain 5 grams of water.
In the second example test case, three moves are enough:
- Pour 3 grams of water from the first vessel into the second one. After this move, the first vessel will contain 17−3=14 grams of water, and the second vessel will contain 4+3=7 grams.
- Pour 2 grams of water from the first vessel into the second one. After this move, the first vessel will contain 14−2=12 grams of water, and the second vessel will contain 7+2=9 grams.
- Finally, pour 1.5 grams of water from the first vessel into the second one. After this move, the first vessel will contain 12−1.5=10.5 grams of water, and the second vessel will contain 9+1.5=10.5 grams.
Note that this is not the only way to equalize the vessels in 3 moves, but there is no way to do it in 2 moves.
In the third example test case, the vessels initially contain the same amount of water, so no moves are needed. The answer is 0.
在第一个测试用例中,只需一次操作即可:若将第二个容器中的 2 克水倒入第一个容器,则两个容器都将含有 5 克水。
在第二个示例测试用例中,三次操作即足够:
- 将第一个容器中的 3 克水倒入第二个容器。此次操作后,第一个容器将含有 17−3=14 克水,第二个容器将含有 4+3=7 克水。
- 将第一个容器中的 2 克水倒入第二个容器。此次操作后,第一个容器将含有 14−2=12 克水,第二个容器将含有 7+2=9 克水。
- 最后,将第一个容器中的 1.5 克水倒入第二个容器。此次操作后,第一个容器将含有 12−1.5=10.5 克水,第二个容器将含有 9+1.5=10.5 克水。
注意:这并非在 3 次操作内使两容器水量相等的唯一方法,但不存在仅用 2 次操作即可实现的方法。
在第三个示例测试用例中,两容器初始水量相同,因此无需任何操作。答案为 0。
输入解题思路,AI测评打分。不知道怎么写?