博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SPOJ ATOMS - Atoms in the Lab
阅读量:4634 次
发布时间:2019-06-09

本文共 1656 字,大约阅读时间需要 5 分钟。

题目链接

题目大意:有N个原子,他们每秒分裂成K个新原子,新原子也能继续分裂。问如果要控制他的数量为M以内,应在什么时候使其停止分裂。其实时间为0.

解题思路:可以发现其实就是一个求log的公式,只不过需要注意M小于N的情况。

代码:

1 const int maxn = 1e6 + 5; 2 ll n, k, m; 3  4 void solve(){ 5     if(m < n) { 6         cout << 0 << endl; return; 7     } 8     double tmp = log(m / n) / log(k); 9     ll ti = floor(tmp);10     cout << ti << endl;11 }12 int main(){13     ios::sync_with_stdio(false);14     int t;15     cin >> t;16     while(t--){17         cin >> n >> k >> m;18         solve();19     }20 }

题目:

ATOMS - Atoms in the Lab

 

 

Mr. Yagami is a scientist in the Bhabha Atomic Research Centre. They are conducting a lab experiment on nuclear fission. In nuclear fission, one atom breaks into more than one atom of the same type.

Initially, there are N atoms in the lab. Starting from now (t=0), after each second, every atom will break into K atoms of the same type. They don’t want the number of atoms to exceed M, so they have to stop the reaction at some time t=T. Can you find this value T for Mr. Yagami.

Input Format:

First line contains P, the number of test cases. Next P lines contain three integers each. These three integers represent the values of N, K and M respectively.

Output Format:

For each test case print the time at which the reaction will have to be stopped.

Constraints:

1 ≤ P ≤ 10^4

2 ≤ N, K, M ≤ 10^18

Sample Input:

22 2 72 2 8

Sample Output:

12

Explanation:

1st test case: 

at t=1, number of atoms=4
at t=2, number of atoms will be 8.
So reaction has to be stopped at t=1.
2nd test case:
at t=1, number of atoms=4
at t=2, number of atoms will be 8.
at t=3, number of atoms will be 16.

转载于:https://www.cnblogs.com/bolderic/p/7395679.html

你可能感兴趣的文章
django-debug-toolbar使用指南
查看>>
2nd 四人小组项目的进一步分析
查看>>
http账户密码的截取
查看>>
LoadRunner中log的使用总结
查看>>
time 和 datetime 模块
查看>>
maven
查看>>
一.Timesten安装
查看>>
微软安全新闻聚焦-双周刊第三十四期
查看>>
xcode target
查看>>
js循环动态绑定带参数函数遇到的问题及解决方案[转]
查看>>
javamail gmail
查看>>
Linux C连接Mysql
查看>>
MyEclipse提示键配置、提示快捷键、提示背景色、关键字颜色、代码显示
查看>>
ATL的GUI程序设计(3)
查看>>
25个iptables常用示例
查看>>
react-navigation
查看>>
【DSP开发】C6000非多核非KeyStone系列DSP中断系统
查看>>
Ubuntu下如何解压缩zip,tar,tar.gz,tar.bz2文件
查看>>
Jenkins实现SVN+Maven+Java项目的持续集成
查看>>
Java:全局变量(成员变量)与局部变量
查看>>