Codeforces 569 A. Music ( 模拟 )
2015-08-12 15:19
417 查看
题目链接:http://codeforces.com/problemset/problem/569/A
题 意:给你一首歌的播放时间T,下载S秒后开始播放,对于任意第q秒可以下载q-1的内容(即每秒下载歌曲q-1/q秒)。
而播放的速度比下载的快,每当播放到没下载的地方,就好从头开始播放,问从头开始播放的次数。
思 路:模拟追击问题,设temp秒后听到没有下载的地方,得到temp*(q-1)/q + S = temp 即 temp = q*S,所以要求temp>= q*S.
代码如下:#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#include <stack>
#include <algorithm>
#define maxn 1179861
int main()
{
int T, S, Q;
while( scanf ( "%d %d %d", &T, &S, &Q ) != EOF )
{
int ans = 0;
while( S < T )
{
S *= Q;
ans++;
}
printf("%d\n",ans);
}
return 0;
}
题 意:给你一首歌的播放时间T,下载S秒后开始播放,对于任意第q秒可以下载q-1的内容(即每秒下载歌曲q-1/q秒)。
而播放的速度比下载的快,每当播放到没下载的地方,就好从头开始播放,问从头开始播放的次数。
思 路:模拟追击问题,设temp秒后听到没有下载的地方,得到temp*(q-1)/q + S = temp 即 temp = q*S,所以要求temp>= q*S.
代码如下:#include <iostream>
using namespace std;
#include <string.h>
#include <stdio.h>
#include <stack>
#include <algorithm>
#define maxn 1179861
int main()
{
int T, S, Q;
while( scanf ( "%d %d %d", &T, &S, &Q ) != EOF )
{
int ans = 0;
while( S < T )
{
S *= Q;
ans++;
}
printf("%d\n",ans);
}
return 0;
}
相关文章推荐
- Javascript SHA-1:Secure Hash Algorithm
- [转]可视化的数据结构和算法
- 统计文件中不小于某一长度的单词的个数(泛型算法实现)
- 使用他人的MD5编码类,修改形成密码串
- Extracting Structured Data from Web Pages
- (译)Cocos2d_for_iPhone_1_Game_Development_Cookbook:1.13使用CCTexture2DMutable调换调色盘
- Java中3DES加密
- Refactoring Notes-Refactoring Methods(3)
- 图书馆管理程序~~不过貌似功能!!有空再修修
- trainging contest#2(2011成都现场赛)I BY Hyoga
- C/C++头文件包含内容概览
- Codeforces Round #197 (Div. 2)
- Codeforces Round #198 (Div. 1)
- 堆栈的应用(1) 平衡符号 C++实现
- 程序员编程艺术第一章、左旋转字符串
- 程序员编程艺术:第三章续、Top K算法问题的实现
- 程序员编程艺术:第四章、现场编写类似strstr/strcpy/strpbrk的函数
- 十四、第三章再续:快速选择SELECT算法的深入分析与实现
- 程序员编程艺术:第七章、求连续子数组的最大和
- 程序员编程艺术:第八章、从头至尾漫谈虚函数