CDOJ 3 BiliBili, ACFun… And More! 模拟

原题链接:http://acm.uestc.edu.cn/#/problem/show/3

题意:

有个人在看B站视频时有个习惯,就是每当卡住的时候,他总再次从头开始看。另外,他在看视频时会先等待T的时间。现在给出播放的速度X和下载的速度Y,总长度S,问你他需要多少时间才能把整个视频都看完。

题解:

不断的跑追击问题就好,不过需要注意边界的情况。

代码:

#include<iostream>
#include<cstring>
#include<algorithm>
#include<iomanip>
using namespace std;

int X,Y,T,S;
int TT;

int main() {
    cin.sync_with_stdio(false);
    cin >> TT;
    int cas = 0;
    while (TT--) {
        cin >> X >> Y >> T >> S;
        cout<<"Case #"<<++cas<<": ";
        if (X <= Y || S <= Y * T) {
            cout << setprecision(3) << fixed << (double) S / X << endl;
            continue;
        }
        double L = Y * T;
        double now = 0;
        while (true) {
            double t = L / (X - Y);
            if (L + Y * t >= S) {
                now += (double) S / X;
                break;
            }
            now += t;
            L += Y * t;
        }
        cout << setprecision(3) << fixed << now << endl;
    }
    return 0;
}

 

posted @ 2015-09-28 13:30  好地方bug  阅读(381)  评论(0编辑  收藏  举报