ACM——Chasing problem

Introduction

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=1XYTY

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=XXYTY

In fact we can see the law inside it:

Tn=Xn1(XY)n

It’s a equidistant series,which means we can use the formula to calculate its summary:

Formula:Sn=1qn1q

the variable q is equal ratio

Now we got everything but the variable n,which means the number of times for totally play.We use the following formula:

n=ceil(logS/(YT)X/(XY))

ceil means get the smallest number among the numbers bigger than the result of parameter

The last thing you have to notice is that the real time consumed
T=Sn+S/X

S/X is the time of last time he play

Eventually,you just need to trans the theory into code,and the following is my code:

    #include "iostream"
    #include "cmath"
    #include "cstdlib"
    using namespace std;

    int main(int argc, char const *argv[])

    {
        int T;
        double time;
        double X,Y,S;
        int case_number;
        cin >> case_number;

        cout.setf(ios::fixed);
        cout.setf(ios::showpoint);
        cout.precision(3);

        for(int i=1;i<=case_number;i++)
        {
            cin >> X >> Y >> T >> S;
            if((X<=Y) || (Y*T>=S))
                time = S/X;
            else{
                int n = ceil(log(S / (Y * T)) / log(X / (X - Y)));
                time = T*(pow(X/(X-Y),n-1)-1) + S/X;
            }
            cout << "Case #" << i << ": " << time << endl;
        }
        return 0;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值