SPOJ ATOMS - Atoms in the Lab

Posted EricJeffrey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SPOJ ATOMS - Atoms in the Lab相关的知识,希望对你有一定的参考价值。

题目链接http://www.spoj.com/problems/ATOMS/

题目大意:有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:

2
2 2 7
2 2 8

Sample Output:

1
2

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.

以上是关于SPOJ ATOMS - Atoms in the Lab的主要内容,如果未能解决你的问题,请参考以下文章

726. Number of Atoms

[LeetCode] Number of Atoms 原子的个数

leetcode726. Number of Atoms

Atoms Atelier本源实验室2020Fall申请辅导全面启动

css 提供固定(粘性)标题和主要导航栏 - 由Junior Atoms提供:http://cobaltapps.club/forum/main-category/web-design-talk/47

Clojure 中纸牌游戏的状态