HarryGuo2012

原题链接: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;
}

 

分类:

技术点:

相关文章:

  • 2021-11-02
  • 2022-01-18
  • 2021-07-16
  • 2022-01-03
  • 2021-06-27
  • 2021-08-31
  • 2021-12-25
猜你喜欢
  • 2021-10-06
  • 2021-10-06
  • 2021-10-06
  • 2021-10-06
  • 2021-10-06
  • 2022-01-09
  • 2021-10-06
相关资源
相似解决方案