Codeforces 189A About Bacteria
来源:互联网 发布:景云网络防病毒 编辑:程序博客网 时间:2024/06/07 01:43
Codeforces Round #125 (Div. 1) A
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
没有计算最坏情况是否超过int64,导致wa了一次。
这题需要推导一下再做
题意是一个培养皿里面的细菌前一秒钟有x个,下一秒就会繁殖到kx+b个。
假设在第一次试验中,这个培养皿第一秒钟放进去1个,过了n秒钟达到了z个。
当第二次实验在培养皿第一秒钟放进去t个,问至少经过多少秒钟使得培养皿的细菌数大于等于z个。
要把递推式转化成闭形式(即得到函数F(n)表示n秒钟细菌有F(n)个)
代码如下
#include <stdio.h>int main(){ int i,ans,j,k,b,n,t; __int64 l,r; scanf("%d%d%d%d",&k,&b,&n,&t); if (k==1) { l=n; l=1+l*b-t; printf("%I64d\n",l/b+(l%b!=0)>=0?l/b+(l%b!=0):0); return 0; } r=k; r=r*t+b-t; l=k+b-1; ans=0; while(l<=r) { ans++; l*=k; } ans--; printf("%d\n",n-ans>=0?(n-ans):0); return 0;}
- Codeforces 189A About Bacteria
- Codeforces Round #125A About Bacteria
- Codeforces Round #125 (Div. 1) A. About Bacteria
- codeforces 199C About Bacteria
- CodeForces 579A - Raising Bacteria
- CodeForces 579A Raising Bacteria
- codeforces 579A Raising Bacteria
- Raising Bacteria CodeForces - 579A
- CodeForces 579A Raising Bacteria (水)
- Codeforces 579A. Raising Bacteria(位运算)
- Codeforces 320A - Raising Bacteria(思维)
- Codeforces Round #125 (Div. 2) / C. 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—— 579A —— Raising Bacteria
- A. Raising Bacteria
- C# 枚举绑定到ComboBox
- 大端、小端模式,网络字节序,多字节字符、Unicorn字符存储
- 面经6.30
- 第一份工作应该做什么?
- superAdmin: Quickly change the status of EmailReport && Property
- Codeforces 189A About Bacteria
- U-boot中常用参数设定及常用宏的解释和说明
- tftp-server配置
- 基类指针和子类指针相互赋值
- 生日问题
- java 获取当前路径:
- Socket通讯
- 如何在Apache环境下配置Rewrite规则
- LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup 问题的解决