codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1359C.md (2232B)


      1 Source: https://codeforces.com/problemset/problem/1359/C
      2 
      3 C. Mixing Water
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 There are two infinite sources of water:
     22 
     23 * hot water of temperature $h$;
     24 * cold water of temperature $c$ ($c \lt h$).
     25 
     26 You perform the following procedure of alternating moves:
     27 
     28 1. take one cup of the hot water and pour it into an infinitely deep barrel;
     29 2. take one cup of the cold water and pour it into an infinitely deep barrel;
     30 3. take one cup of the hot water $\dots$
     31 4. and so on $\dots$
     32 
     33 Note that you always start with the cup of hot water.
     34 
     35 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.
     36 
     37 You want to achieve a temperature as close as possible to $t$. So if the temperature in the barrel is $t_b$, then the absolute difference of $t_b$ and $t$ ($|t_b - t|$) should be as small as possible.
     38 
     39 How many cups should you pour into the barrel, so that the temperature in it is as close as possible to $t$? If there are multiple answers with the minimum absolute difference, then print the smallest of them.
     40 
     41 Input
     42 
     43 The first line contains a single integer $T$ ($1 \le T \le 3 \cdot 10^4$) — the number of testcases.
     44 
     45 Each of the next $T$ lines contains three integers $h$, $c$ and $t$ ($1 \le c \lt h \le 10^6$; $c \le t \le h$) — the temperature of the hot water, the temperature of the cold water and the desired temperature in the barrel.
     46 
     47 Output
     48 
     49 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 $t$.
     50 
     51 Example
     52 
     53 Input
     54 
     55 ```
     56 3
     57 30 10 20
     58 41 15 30
     59 18 13 18
     60 ```
     61 
     62 Output
     63 
     64 ```
     65 2
     66 7
     67 1
     68 ```
     69 
     70 Note
     71 
     72 In the first testcase the temperature after $2$ poured cups: $1$ hot and $1$ cold is exactly $20$. So that is the closest we can achieve.
     73 
     74 In the second testcase the temperature after $7$ poured cups: $4$ hot and $3$ cold is about $29.857$. Pouring more water won't get us closer to $t$ than that.
     75 
     76 In the third testcase the temperature after $1$ poured cup: $1$ hot is $18$. That's exactly equal to $t$.