Kattis, Kattis 的一些问题题解

Posted xuwanwei

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Kattis, Kattis 的一些问题题解相关的知识,希望对你有一定的参考价值。

题目链接

(Thanos)[https://open.kattis.com/problems/thanos]

题目

Thanos
Dr. Thanos, data scientist and self-described nihilist, recently published a paper titled The snapping point of the universe: why rates of population growth point towards imminent destruction. In his paper, Thanos explains that in many planets, the increasing population count is leading to a diminished quality of life. He is convinced that his findings will drive sweeping reforms in intergalactic law, leading to a better life for all organisms.

Thanos turns to you, his confidant, to do some investigation. He would like some concrete evidence for his findings to present to the Association of VENGE’s Research Society. The society, one of the galatic leaders in egalitarianism and social justice, is holding a special panel to discuss Thano’s findings. As this involves the chance of actual legislation being passed, Thanos is convinced that the panelists are going to be a tough sell. He asks you to investigate several datasets and see if they could be potentially helpful in supporting his argument.

Thanos hands you the data for several planets. On each planet’s file, you read that: the planet currently has a population of P, its population grows by a factor of R times per year, and its annual food production F in tons. All food produced in a year must be consumed that year; it cannot be saved. Assume that each individual consumes 1 ton of food per year, and that the population for each planet each year is always counted as a whole number, rounded down. Given this information, your task is to find out the number of years a planet has remaining before its population is no longer sustainable by its food production.

Input
The first line of input consists of a single integer T (1≤T≤2000), the number of planets that need to be analyzed.
T lines follow, the ith of which consists of three space-separated integers (P (1≤P≤10^9), R (1<R≤10^9)), and (F (1≤F≤10^9)), the metrics of planet i as described above.

Output
Print T lines, the ith of which should consist of a single integer denoting the number of years the ith planet has before it is no longer sustainable.

题意

有T组数据,每组数据给你三个数P,R, F, P每年人数增长R倍,一个人一年吃1吨食物,每年有F吨食物而且多的不能留到下一年,问你可以这个星球离毁灭还有多少年?

思路

  • 我一开始用公式做,一直WA, 开始怀疑是精度的问题
  • 所有这种题目能直接暴力枚举就不要用公式 噫吁戱

代码

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll P,R,F;
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%lld%lld%lld",&P,&R,&F);
		ll ans=0;
		while(P<=F)
		{
			ans++;
			P*=R; 
		}
		printf("%lld
",ans);
	}
	return 0;
}




以上是关于Kattis, Kattis 的一些问题题解的主要内容,如果未能解决你的问题,请参考以下文章

Kattis amazingadventures Amazing Adventures(费用流路径)题解

Kattis - bitwise Bitwise (RMQ+尺取+树上dfs)

在 Kattis 上识别地图图块超过了时间限制

Kattis-Beekeeper

Kattis-Beekeeper

Kattis-Black Friday