題目
輸入觀看視頻的播放速度扇售,緩沖速度藕届,播放前等待時(shí)間和視頻總時(shí)長(zhǎng),當(dāng)播放到還未被緩存的地方鲸湃,將從頭開(kāi)始播放(真煩人赠涮。。)題目鏈接
思路
畫(huà)出兩條直線的函數(shù)圖就很清晰了
代碼
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int cs; cin >> cs;
for(int T=1; T<=cs;T++){
bool flag=1;
float pl, dl, wt, s,t=0;
cin >> pl >> dl >> wt >> s;
float x,y,x0=wt;
if(pl<=dl){ //播放速度比緩存速度慢
cout << "Case #"<< T <<": "<< fixed<<setprecision(3)<<s/pl;
if(T<cs) cout << "\n";
continue;
}
while(flag){
x = pl*x0/(pl-dl); //播放與緩存相交的地方
y = x*dl;
if(y>=s) {
flag=0;
t+=s/pl;
}
else {
x0 = x; t = x-wt;
}
}
if(!flag) cout << "Case #"<<T<<": "<< fixed<< setprecision(3)<<t;
if(T<cs) cout << "\n";
}
return 0;
}