A. Music(Codeforces Round #315 (Div. 2) 求最大的容纳量)

来源:互联网 发布:剑侠情缘3网游mac 编辑:程序博客网 时间:2024/06/05 06:30
A. Music
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Little Lesha loves listening to music via his smartphone. But the smartphone doesn't have much memory, so Lesha listens to his favorite songs in a well-known social network InTalk.

Unfortunately, internet is not that fast in the city of Ekaterinozavodsk and the song takes a lot of time to download. But Lesha is quite impatient. The song's duration is T seconds. Lesha downloads the first S seconds of the song and plays it. When the playback reaches the point that has not yet been downloaded, Lesha immediately plays the song from the start (the loaded part of the song stays in his phone, and the download is continued from the same place), and it happens until the song is downloaded completely and Lesha listens to it to the end. For q seconds of real time the Internet allows you to download q - 1 seconds of the track.

Tell Lesha, for how many times he will start the song, including the very first start.

Input

The single line contains three integers T, S, q (2 ≤ q ≤ 1041 ≤ S < T ≤ 105).

Output

Print a single integer — the number of times the song will be restarted.

Sample test(s)
input
5 2 2
output
2
input
5 4 7
output
1
input
6 2 3
output
1
Note

In the first test, the song is played twice faster than it is downloaded, which means that during four first seconds Lesha reaches the moment that has not been downloaded, and starts the song again. After another two seconds, the song is downloaded completely, and thus, Lesha starts the song twice.

In the second test, the song is almost downloaded, and Lesha will start it only once.

In the third sample test the download finishes and Lesha finishes listening at the same moment. Note that song isn't restarted in this case.



     题意:一首歌会播放T秒,在第一次播放之前先缓冲s秒,播放后每q秒就会缓冲q-1秒的音乐,如果音乐播放到某一个地方但是还没有缓冲到,音乐就会重新开始播放,现在问音乐播放完毕时音乐重新播放了几次

点击打开链接



#include <iostream>using namespace std;int t,s,q;int main(){    while(cin >> t >> s >> q)    {        int x = s;        int y=0;        int cnt=1;        while(x<t)        {            if(y+q<( x+q-1))            {                x = x+q-1;                y=y+q;            }            else if((y+q)==(x+q-1) )            {                if(y+q<t)                {                    cnt++;                    x=y+q;                    y=0;                }                else                {                    x=t;                }            }            else            {                x +=q-1;                cnt++;                y=0;            }        }        cout << cnt << endl;    }    return 0;}


0 0
原创粉丝点击