# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
# | User | Contrib. |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Name |
---|
Hint: the function is decreasing at odd number of cups. and the function is constant at even number of cups. Look at this graph:
![ ]()
Let's deal with the base case first. Let avg=(h+c)/2. Now temperature will never go below this. So if t<=avg, the answer is 2. Now, for all even no. of moves answer be average and for odd, the answer will tend towards avg. The temperature function after 'x+1' cups of hot water will be — ((x+1)*h + x*c )/(2*x+1). we can see that this tends to 'avg' as x tends to inf. Note here that the total moves are 2*x+1 which is always odd. Let's denote the total moves by 'n'(2*x+1). When n=1, temp is h, and as n increases, temp. keeps decreasing and tends to avg. (At n=inf, temp=avg).Now let's do binary search on the value of x. For some x, 't' will lie between temp at x and x+1. So low=0,hi=(some high value). We will calculate the value at mid and mid+1. I think further approach should be clear. If not, feel free to ask. Here is an implementation of above explained method:- 81782877
Why did you do "h=(h-beg)" in your code?
That part is just to shift the average. Like in physics you subtract C.O.M. to see in respect of C.O.M. You can actually solve it without shifting average.