• A. Two Vessels


    time limit per test

    1 second

    memory limit per test

    256 megabytes

    input

    standard input

    output

    standard output

    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.

    Input

    Each test contains multiple test cases. The first line contains the number of test cases t� (1≤t≤10001≤�≤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≤1001≤�,�,�≤100) — 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.

    Example

    input

    Copy

     
    

    6

    3 7 2

    17 4 3

    17 17 1

    17 21 100

    1 100 1

    97 4 3

    output

    Copy

    1
    3
    0
    1
    50
    16
    

    Note

    In the first test case, only one move is enough: if we pour 22 grams of water from the second vessel into the first one, both vessels will contain 55 grams of water.

    In the second example test case, three moves are enough:

    • Pour 33 grams of water from the first vessel into the second one. After this move, the first vessel will contain 17−3=1417−3=14 grams of water, and the second vessel will contain 4+3=74+3=7 grams.
    • Pour 22 grams of water from the first vessel into the second one. After this move, the first vessel will contain 14−2=1214−2=12 grams of water, and the second vessel will contain 7+2=97+2=9 grams.
    • Finally, pour 1.51.5 grams of water from the first vessel into the second one. After this move, the first vessel will contain 12−1.5=10.512−1.5=10.5 grams of water, and the second vessel will contain 9+1.5=10.59+1.5=10.5 grams.

    Note that this is not the only way to equalize the vessels in 33 moves, but there is no way to do it in 22 moves.

    In the third example test case, the vessels initially contain the same amount of water, so no moves are needed. The answer is 00.

    解题说明:此题是一道数学题,由于不需要舀子每次装满水,那么直接计算即可。先判断平均值,然后判断需要舀多少次。

    1. #include
    2. #include
    3. int main()
    4. {
    5. int a, b, c, n, i, m;
    6. float move;
    7. scanf("%d", &n);
    8. for (i = 1; i <= n; i++)
    9. {
    10. scanf("%d %d %d", &a, &b, &c);
    11. move = (float)(abs(a - b)) / (2 * c);
    12. m = (int)(ceil(move));
    13. printf("%d\n", m);
    14. }
    15. return 0;
    16. }

  • 相关阅读:
    第一节 vue3 router内置类型有哪些
    『牛客|每日一题』岛屿数量
    关于ETL的两种架构(ETL架构和ELT架构)
    LeetCode-数组-No41缺失的第一个正数
    select......for update会锁表还是锁行?
    Server-Sent Events(以下简称 SSE)及event-source-polyfill使用
    文档对象模型 DOM ——让JS有能力和网页进行对话
    一种非线性权重的自适应鲸鱼优化算法IMWOA附matlab代码
    Python图形处理
    js回到顶部或定位到指定元素
  • 原文地址:https://blog.csdn.net/jj12345jj198999/article/details/132912339