CF1359C.Mixing Water

普及+/提高

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

There are two infinite sources of water:

  • hot water of temperature hh;
  • cold water of temperature cc (c<hc \lt h).

You perform the following procedure of alternating moves:

  1. take one cup of the hot water and pour it into an infinitely deep barrel;
  2. take one cup of the cold water and pour it into an infinitely deep barrel;
  3. take one cup of the hot water …\dots
  4. and so on …\dots

Note that you always start with the cup of hot water.

The barrel is initially empty. You have to pour at least one cup into the barrel. The water temperature in the barrel is an average of the temperatures of the poured cups.

You want to achieve a temperature as close as possible to tt. So if the temperature in the barrel is tbt_b, then the absolute difference of tbt_b and tt (∣tb−t∣|t_b - t|) should be as small as possible.

How many cups should you pour into the barrel, so that the temperature in it is as close as possible to tt? If there are multiple answers with the minimum absolute difference, then print the smallest of them.

存在两种无限的水源:

  • 温度为 hh 的热水;
  • 温度为 cc 的冷水(满足 c<hc \lt h)。

你执行如下交替倒水操作:

  1. 取一杯热水,倒入一个无限深的桶中;
  2. 取一杯冷水,倒入该桶中;
  3. 再取一杯热水 …\dots
  4. 如此继续 …\dots

注意:你总是从一杯热水开始。

桶初始为空,且你至少需倒入一杯水。桶中水的温度等于所有已倒入水杯温度的算术平均值。

你的目标是使桶中水温尽可能接近 tt。即若桶中实际水温为 tbt_b,则应使绝对差值 ∣tb−t∣|t_b - t| 尽可能小。

你需要倒入多少杯水,才能使桶中水温最接近 tt?若存在多个倒入杯数使得绝对差值均达到最小,则输出其中最小的杯数。

输入格式

The first line contains a single integer TT (1≤T≤3⋅1041 \le T \le 3 \cdot 10^4) — the number of testcases.

Each of the next TT lines contains three integers hh, cc and tt (1≤c<h≤1061 \le c \lt h \le 10^6; c≤t≤hc \le t \le h) — the temperature of the hot water, the temperature of the cold water and the desired temperature in the barrel.

第一行包含一个整数 TT(1≤T≤3⋅1041 \le T \le 3 \cdot 10^4)—— 测试用例的数量。

接下来的 TT 行中,每行包含三个整数 hh、cc 和 tt(1≤c<h≤1061 \le c \lt h \le 10^6;c≤t≤hc \le t \le h)—— 分别表示热水温度、冷水温度以及桶中期望达到的温度。

输出格式

For each testcase print a single positive integer — the minimum number of cups required to be poured into the barrel to achieve the closest temperature to tt.

对于每个测试用例,输出一个正整数——为使桶中液体温度最接近 tt 所需倒入桶中的最少杯子数量。

输入输出样例

  • 输入#1

    3
    30 10 20
    41 15 30
    18 13 18

    输出#1

    2
    7
    1

说明/提示

In the first testcase the temperature after 22 poured cups: 11 hot and 11 cold is exactly 2020. So that is the closest we can achieve.

In the second testcase the temperature after 77 poured cups: 44 hot and 33 cold is about 29.85729.857. Pouring more water won't get us closer to tt than that.

In the third testcase the temperature after 11 poured cup: 11 hot is 1818. That's exactly equal to tt.

在第一个测试用例中,倒入 2 杯水(1 杯热水和 1 杯冷水)后的温度恰好为 2020。因此这是所能达到的最接近目标温度的结果。

在第二个测试用例中,倒入 7 杯水(4 杯热水和 3 杯冷水)后的温度约为 29.85729.857。继续加水无法使温度比该值更接近 tt。

在第三个测试用例中,倒入 1 杯水(1 杯热水)后的温度为 1818,恰好等于 tt。

输入解题思路,AI测评打分。不知道怎么写?

首页