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

#math #big-numbers

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.

时间: 2025-02-01 06:37:44

SPOJ ATOMS - Atoms in the Lab的相关文章

Molecule to atoms

For a given chemical formula represented by a string, count the number of atoms of each element contained in the molecule and return an object. 1 water = 'H2O' 2 parse_molecule(water) 3 # return {H: 2, O: 1} 4 5 magnesium_hydroxide = 'Mg(OH)2' parse_

[LeetCode] Number of Atoms 原子的个数

Given a chemical formula (given as a string), return the count of each atom. An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name. 1 or more digits representing the count of that elem

【leetcode】726. Number of Atoms

题目如下: 解题思路:我用的是递归的方法,每次找出与第一个')'匹配的'('计算atom的数量后去除括号,只到分子式中没有括号为止.例如 "K4(ON(SO3)2)2" -> "K4(ONS2O6)2" -> "K4O2N2S4O12".接下来再对分子式进行分割,得出每个atom的数量后排序即可.原理很简单,代码写得很乱,仅供参考. 代码如下: class Solution(object): def recursive(self,fo

726.&#160;Number of Atoms

Given a chemical formula (given as a string), return the count of each atom. An atomic element always starts with an uppercase character, then zero or more lowercase letters, representing the name. 1 or more digits representing the count of that elem

SPOJ 705 Distinct Substrings(后缀数组)

[题目链接] http://www.spoj.com/problems/SUBST1/ [题目大意] 给出一个串,求出不相同的子串的个数. [题解] 对原串做一遍后缀数组,按照后缀的名次进行遍历, 每个后缀对答案的贡献为n-sa[i]+1-h[i], 因为排名相邻的后缀一定是公共前缀最长的, 那么就可以有效地通过LCP去除重复计算的子串. [代码] #include <cstdio> #include <cstring> #include <algorithm> usi

SPOJ 3273

传送门: 这是一道treap的模板题,不要问我为什么一直在写模板题 依旧只放代码 1 //SPOJ 3273 2 //by Cydiater 3 //2016.8.31 4 #include <iostream> 5 #include <cstring> 6 #include <ctime> 7 #include <cmath> 8 #include <cstdlib> 9 #include <string> 10 #include

Simulation.Lab.Software.SimLab.Composer.2015.v6.1.MACOSX 1CD

CA Spectrum Linux VM 10.01.00.00.103 Linux 2DVD  Tahoe Design HYDROFLO v3.0.0.4 1CD  CA Spectrum Windows VM 10.01.00.00.103 Win64 2DVD  Delcam Exchange 2016 R2 CR 8.3.1005 Win64 1CD  Delcam PowerSHAPE 2016 SP2 Update only 1CD  ESI Group VA One 2015.0

x01.Lab.StoreApp: XP 停服,微软变脸

变脸,川剧的一种表演形式,除了哄哄小孩,似乎别无用处.而川剧变脸从业者何其多也,存在时间何其长也.以如此多的从业者,如此长的时间,来进行科研,其成果一定是斐然吧.推而广之,试问天下谁能敌! 微软变脸,足以改变世界.这次变脸,不仅是形式上的,而且是骨子里的.为适应手机.平板的性能苛求,其应用商店程序是建立在 WinRT 的基础上,而 WinRT 是建立在 COM 基础上.即面向对象,又拥抱底层,可谓鱼与熊掌兼得.不仅如此,其开发者许可,应用商店成立,无一不在显示微软的掌控能力."天下英雄,尽入毂中

SPOJ CRAN02 - Roommate Agreement

题目链接:http://www.spoj.com/problems/CRAN02/ 题目大意:N个数字组成的序列,和为0的连续子序列的个数.N<1e6 解题思路:计算前缀和,统计每个数字出现的次数,那么对于数字sum[i], 如果存在k个sum[i],则代表有C(k, 2)个序列和为0,而如果sum[i] = 0,则还要累加上对应的k值. 代码: 1 ll n; 2 int a[maxn]; 3 ll sum[maxn]; 4 map<int, int> mmp; 5 6 void so