Codeforces Round #125A About Bacteria
来源:互联网 发布:photoshopcs3软件下载 编辑:程序博客网 时间:2024/06/05 13:34
Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high.
At the beginning of the first experiment there is a single bacterium in the test tube. Every second each bacterium in the test tube divides itself intok bacteria. After that some abnormal effects createb more bacteria in the test tube. Thus, if at the beginning of some second the test tube hadx bacteria, then at the end of the second it will havekx + b bacteria.
The experiment showed that after n seconds there were exactlyz bacteria and the experiment ended at this point.
For the second experiment Qwerty is going to sterilize the test tube and put theret bacteria. He hasn't started the experiment yet but he already wonders, how many seconds he will need to grow at leastz bacteria. The ranger thinks that the bacteria will divide by the same rule as in the first experiment.
Help Qwerty and find the minimum number of seconds needed to get a tube with at leastz bacteria in the second experiment.
The first line contains four space-separated integers k,b,n andt(1 ≤ k, b, n, t ≤ 106) — the parameters of bacterial growth, the time Qwerty needed to growz bacteria in the first experiment and the initial number of bacteria in the second experiment, correspondingly.
Print a single number — the minimum number of seconds Qwerty needs to grow at leastz bacteria in the tube.
3 1 3 5
2
1 4 4 7
3
2 2 4 100
0
这题就是要你得到一个递推公式 x(i+1)=k * x(i) + b; 实验一的x1(0)=1, 实验二的x2(0)=t; 目标是:求最小的q, 使得x2(q)>=x1(n);
当k!=1时,对于递推公式,令h=b/(k-1), y(i)=x(i)+b, 则y(i+1)=k * y(i), 既y(i)是以y(0)为首项,k为公比的等比数列。由于实验一和实验二的首项已知,x(n)=k^n * (x(0)+h)-h;
为了避免小数和log运算产生精度误差,等式两边同时乘以k-1, 最后得到不等式(k-1+b) * k^(n-q)<=(k-1) * t + b, 其中q要尽可能小(废话,求最少的天数)。求法是令i=n-q, i尽可能大既可。
当k=1时,x(n)就是等差数列,直接算出答案就可以了。
由于(k-1)*t超过了int , 所以读入时就要__int64 !!!!!
#include <iostream>
#include <math.h>
using namespace std;
int main(){
__int64 k,b,n,t,q,i;
cin>>k>>b>>n>>t;
if (k>1){
__int64 tmp;
__int64 abc;
tmp=(k-1+b);
i=0;q=0;abc=(k-1)*t+b;
while (tmp<=abc) {i++;tmp*=k;}i--;
q=n-i;
}
else {
q=0;
while (q*b+t<n*b+1) q++;
}
if (q<0) q=0;
cout<<q<<endl;
return 0;
}
- Codeforces Round #125A About Bacteria
- Codeforces Round #125 (Div. 1) A. About Bacteria
- Codeforces 189A About Bacteria
- Codeforces Round #125 (Div. 2) / C. About Bacteria
- codeforces 199C About Bacteria
- Codeforces Round #320 (Div. 2) A. Raising Bacteria
- Codeforces Round #320 (Div. 2) 579A Raising Bacteria(脑洞)
- Codeforces Round #320 (Div. 2) 579A. Raising Bacteria
- Codeforces Round #320 (Div. 2) A. Raising Bacteria
- Codeforces Round #320 (Div. 2) [Bayan Thanks-Round]A Raising Bacteria
- CodeForces 579A - Raising Bacteria
- CodeForces 579A Raising Bacteria
- codeforces 579A Raising Bacteria
- Raising Bacteria CodeForces - 579A
- Codeforces Round #320 (Div. 1) A. A Problem about Polyline
- CodeForces 579A Raising Bacteria (水)
- Codeforces 579A. Raising Bacteria(位运算)
- Codeforces 320A - Raising Bacteria(思维)
- 一些特殊的有用的SQL写法
- 关于matlab的SVM工具箱的几个函数
- SQL SERVER 2012 - MEMORY MANAGEMENT
- Android图形---OpenGL(三)
- 用语句实现对数据列的操作(SQL SERVER)
- Codeforces Round #125A About Bacteria
- python的exit退出时,提示TypeError: 'str' object is not callable
- 在1-n中1出现的次数(微软等IT公司面试一百题)
- 振作只需一个理由:日子不能这样过
- 拓扑排序
- 对IA32的理解又稍有进步啊!
- 用VS2010制作中文安装包
- xcode4利用Interface Builder布局时如何调整不同控件之间的叠放次序
- 字符编码与汉字编码