The origin problem called BiliBili, ACFun… And More!is put on the website http://acm.uestc.edu.cn.It says that a man want to play and watch video but he has to replay from the beginning if the buffered part is already played when the video is not finished.You should calculate the total time.
Input
The first line of input contains a number TT, indicating the number of test cases. (T≤1000T≤1000).For each case, there will be four integers XX, YY, TT and SS, which is the playing speed, downloading speed, the time kennethsnow will wait before playing, and the total size of video, given in KB. (1≤X,Y,T≤201≤X,Y,T≤20, 1≤S≤1001≤S≤100).
Output
For each case, output Case #i: first. (ii is the number of the test case, from 11 to TT). Then output the time kennethsnow needs to finish watching, in decimals, round to 33 decimal places.
Theory
This problem is totally a math problem.So let’s just calculate it first.
We assume the play speed is faster than buffer speed.So we can calculate the time T1 as follow:
We calculate for the first time:
XT1=TY+YT1
And we can know from above:
T1=1X−YTY
After the first time is finished,he has to restart from the beginning and then we calculate for the second time:
XT2=TY+YT1+YT2
And we can still know from above:
T2=XX−YTY
In fact we can see the law inside it:
Tn=Xn−1(X−Y)n
It’s a equidistant series,which means we can use the formula to calculate its summary:
Formula:Sn=1−qn1−q
thevariableqisequalratio
Now we got everything but the variable n,which means the number of times for totally play.We use the following formula: