Max and Alexis Plan to Conquer the World Gym - 101353B(一个数多少次方要有敏感性,两边取对数)

题目链接:https://vjudge.net/problem/Gym-101353B

题目:
B. Max and Alexis Plan to Conquer the World
Score: 100
CPU: 1.25s
Memory: 1024MB
There is this kitten Alexis. His favorite game is playing football. Then there is another kitten, Max. His
favorite game is biting “hoomans”. So the first time they met, naturally they couldn’t agree on the
game they should play together. So after two minutes of arguing ( as kittens cannot focus on
anything for more than two minutes), Max proposed, “Let’s conquer the world of hoomans. They
have been there for too long. We are the real kings and queens who should rule the kittenland.”
Alexis agreed with Max and immediately they started formulating their masterplan. Now they are
facing a problem. There are N kittens in kittenland currently. Each year the number of kittens
increase by R%. Max has decided that they wouldn’t start their conquest before they have at least P
kittens in their army. So now they are struggling a bit to find out how many years they have to wait till
they can start their conquest. For example, let’s say, there are currently 10 kittens in kittenland. If
their number increases by 15% each year, then there will be 11.5 kittens after one year. So, if they
need 11 kittens to be present in their army, they would need to wait for one year. [ Yes, it is very
much possible that there can be 11.5 kittens. You know, it’s mathematics and stuff. ] Now if you can
solve the problem for queen Max and king Alexis, they might let you go after they conquer the world.
Input
The first line contains a positive integer T, number of test cases. In each of the following T lines,
there will be 3 integers, N, R, and P. ( The number of kittens currently in the kittenland, the
percentage of growth of population each year and the minimum number of kittens needed for the
conquest. )
Output
For each case print the case number and then a single integer which is the number of years, that
Max and Alexis have to wait before starting the conquest.
Sample
Input Output
3
10 15 11
10 15 12
446390799 24 650597780460575459
Case 1: 1
Case 2: 2
Case 3: 99

题意: N是本金,R是年利率,P是想达到的目标金额,求要几年才能到达目标金额。

思路:
两边取对数
x是多少年才能达到目标。

代码:

#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>


using namespace std;

int main()
{
    int t,cs;
    scanf("%d",&t);
    while(t--)
    {
        long long n,p;
        unsigned long long d,ans;
        scanf("%lld %lld %llu",&n,&p,&d);
        if(d<=n)
            printf("Case %d: 0\n",++cs);
        else
        {
            ans =ceil((double)(log(d)-log(n))/log(1+(p/100.0)));//ceil为向上取整函数
            printf("Case %d: %llu\n",++cs,ans);
        }
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值