Codeforces Round #315 (Div. 2)

Description

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.

Sample Input

Input

5 2 2

Output

2

Input

5 4 7

Output

1

Input

6 2 3

Output

1

Sample Output

Case 1: 62.5000000000

Case 2: 150

Hint

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.

目大意:一个人下载歌,每q个时间单位能下载q-1个时间单位的歌,歌的长度为T,下到S的时候开始播放,如果歌还没下完且放到了还未下载的地方,则重头开始放,问一共要放多少次

题目分析:一开始从s开始,设下了x秒后听和下的进度相同,则 s + (q - 1) / q * x = x,解得x= q * s,然后从头开始,设t‘秒后进度相同,则(q - 1) / q * t‘ + x= t‘,解得t‘ = x * q,可见直接拿第一次进度相同的时间乘q就是接下来每次进度相同的.

代码:

#include<cstdio>
using namespace std;
int main()
{
    int T,S,q,x,ans;
   while(scanf("%d%d%d",&T,&S,&q)!=EOF)
   {

        ans=1;
        x=q*S;
        while(x<T)
        {
            x=q*x;
            ans++;
        }
        printf("%d\n",ans);
   }

    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-07 22:11:40

Codeforces Round #315 (Div. 2)的相关文章

Codeforces Round #315 (Div. 1)

A. Primes or Palindromes? time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and un

Codeforces Round #315 (Div. 2) A. Music 解题心得

原题: Description 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

Codeforces Round #315 (Div. 2) (ABCD题)

A. Music 题意: 一首歌长度为S秒,已经下载了T秒,下载速度为每q秒的现实时间能下载下来(q-1)秒 的歌曲.现在开始听歌,如果听到还没下载的地方就从0秒的地方开始replay,求一首歌听完需要从0秒听几次(包括一开始那次) 思路: 我们可以用路程-时间的思路来考虑这道题. 假设两位选手"播放"与"下载","播放"的起点是0m处,"下载"的起点是Tm处,终点在Sm处,"播放"的速度是1m/s,&qu

Codeforces Round #315 (Div. 2)——C. Primes or Palindromes?

这道题竟然是一个大暴力... 题意: π(n):小于等于n的数中素数的个数 rub(n) :小于等于n的数中属于回文数的个数 然后给你两个数p,q,其中A=p/q: 然后要你找到对于给定的A,找到使得π(n)?≤?A·rub(n) 最大的n. (A<=42) 思路: 首先我们可以暴力算出当n为大概150万左右的时候,π(n)大概是 rub(n) 的42倍. 所以我们只需要for到150万左右就好,因为对于后面的式子,肯定能在150万的范围内找到一个n使得这个式子成立的. 而且,我们可以得出因为素

Codeforces Round #315 (Div. 2) 568A Primes or Palindromes?

题目:Click here 题意:π(n)表示不大于n的素数个数,rub(n)表示不大于n的回文数个数,求最大n,满足π(n) ≤ A·rub(n).A=p/q; 分析:由于这个题A是给定范围的,所以可以先暴力求下最大的n满足上式,可以想象下随着n的增大A也在增大(总体正相关,并不是严格递增的),所以二分查找时不行的,所以对给定的A,n是一定存在的.这个题的关键就是快速得到素数表最好在O(n)的时间以内.(杭电15多校的一个题也用到了这个算法点这里查看) 1 #include <bits/std

Codeforces Round #315 (Div. 2) 569B Inventory

题目:Click here 题意:给你n,然后n个数,n个数中可能重复,可能不是1到n中的数.然后你用最少的改变数,让这个序列包含1到n所有数,并输出最后的序列. 分析:贪心. 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int M = 1e5+5; 4 5 int n; 6 int a[M]; // 给定序列 7 int mark[M]; // mark[i] 表示i在给定序列中的出现次数 8 int notap[M];

Codeforces Round #315 (Div. 2)(A,B)

A: 题目地址:Music 题意:你要听一首时长为T秒的歌曲, 你点击播放时会立刻下载好S秒, 当你听到没有加载到的地方时, 就会重头听, 直到可以听完整首歌,由于网络堵塞, 你在q秒内只有q-1秒用于下载, 问需要重新多少次(第一次也算) 思路:这个题很类似于初中学过的追及问题.由于每q秒下载的时间为q-1,所以下载的速度可以确定为(q-1)/q.假设需要T秒才能下完,则有公式T*(q-1)/q+S=T,所以化简的T=q*S,所以下载的次数就是乘以s*q小于T的次数. #include <st

Codeforces Round #315 (Div. 2) 569A Music (模拟)

题目:Click here 题意:(据说这个题的题意坑了不少人啊~~~)题目一共给了3个数---- T 表示歌曲的长度(s).S 表示下载了歌曲的S后开始第一次播放(也就是说S秒的歌曲是事先下载好的).q 表示下载速度(每秒下载歌曲(q-1)/q秒).问题就是播放的速度比下载的速度慢,每当播放到没下载的位置,就会重新从头播放,输出的就是从头播放的次数(包括第一次). 分析:高中物理追击问题,模拟下好了. 1 #include <bits/stdc++.h> 2 using namespace

Codeforces Round #315 (Div. 1) A. Primes or Palindromes? 暴力

A. Primes or Palindromes?Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://poj.org/problem?id=3261 Description Rikhail Mubinchik believes that the current definition of prime numbers is obsolete as they are too complex and unpredictable. A palindro