题目链接:
点击打开链接
题意:Little Lesha 想听一首歌, 这首歌长t秒,Little Lesha 先下载了s秒,边听边下载,每q秒可以下载q-1秒的歌,每当播放到未下载的时候,返回开始从头开始播放,问Little Lesha 下载一首歌需要从头开始多少次。
思路:假定放到未下载点时候用时x秒,那么(q-1)/q就是每秒下载的速度,(q-1)/q*x+s=x。那么x=q*s
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
int t,s,q,ans;
while(scanf("%d%d%d",&t,&s,&q)!=EOF)
{
ans=0;
while(s<t)
{
s=s*q;
ans++;
}
printf("%d\n",ans);
}
return 0;
}
再放一个博主模拟的代码WA到怀疑人生,有兴趣的同学可以帮我改改
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
int main(){
double t,q,s;
cin >> t >> s >> q;
int ans = 0;
int now = 0;
while(s < t){
if(now == 0) ans ++;
now ++;
s += (q-1)/q;
if(now > s)
now = 0;
}
cout << ans << endl;
}