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


    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;
    }


  • 相关阅读:
    数组方法之find
    检查数组中是否有NaN
    数组方法之includes
    数组方法之lastIndexOf
    数组方法之indexOf
    数组方法之forEach
    col-md-push-*和col-md-offset的区别
    35个jQuery小技巧!
    35个jQuery小技巧!
    VS 2013插件
  • 原文地址:https://www.cnblogs.com/liguangsunls/p/6889156.html
Copyright © 2020-2023  润新知