zoukankan      html  css  js  c++  java
  • 【30.49%】【codeforces 569A】Music

    time limit per test2 seconds
    memory limit per test256 megabytes
    inputstandard input
    outputstandard 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 ≤ 104, 1 ≤ S < T ≤ 105).

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

    Examples
    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.

    【题目链接】:http://codeforces.com/contest/569/problem/A

    【题解】

    其实可以看成两辆车的追击问题;
    一辆车A一开始在起点,另一辆B在S位置;
    vA=1,vB=(q-1)/q;
    则设经过了时间t
    sa=t;
    sb=s+(q-1)/q *t
    令sa=sb
    ->t = q*s;
    如果sb< t则sa又变回0,ans递增,此时s变成s+(q-1)/1*t;
    然后重复上述步骤即可;
    有点恶心。

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define rei(x) scanf("%d",&x)
    #define rel(x) scanf("%I64d",&x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    //const int MAXN = x;
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    
    int t,s,q;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        rei(t);rei(s);rei(q);
        int now = s;
        int bo = 0;
        int ans = 1;
        while (now<t)
        {
            //v download ->q/q-1
            int tempt = q*s;
            int d = (q-1)*(tempt/q);
            now+=d;
            if (now >=t) break;
            ans++;
            s = now;
        }
        printf("%d
    ",ans);
        return 0;
    }
  • 相关阅读:
    ubuntu安装gnome桌面,ubuntu系统16升级到18
    重置root密码
    shell中tr的用法
    ubuntu14.04安装zabbix
    TTTTTTTTTTTTTT poj 1127 Jack Straws 线段相交+并查集
    TTTTTTTTTTTTT poj 3057 Evacuation 二分图匹配+bfs
    hdu 1208 Ignatius and the Princess III 划分数,dp
    Poj 3057 未AC http://poj.org/showsource?solution_id=15175171
    poj 3662 Telephone Lines dijkstra+二分搜索
    poj 3684 Physics Experiment 弹性碰撞
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626853.html
Copyright © 2011-2022 走看看