791A.Bear and Big Brother

  • 题目
  • 翻译
    • 题目
    • 输入
    • 输出
  • 分析
  • 代码

题目

翻译

题目

熊Limak想要成为熊族中最重的熊,至少比他的兄弟Bob重。
    现在,Limak和Bob分别重aaa和bbb。可以肯定的是Limak的体重小于等于他兄弟的体重。
    Limak吃了很多,这样每年重量将会变为原来的三倍,而Bob则每年重量变为原来的两倍。
    多少年后Limak的体重才会大于Bob?

输入

只输入2个整数aaa和bbb(1 ≤ a ≤ b ≤ 10) 一 Limak和Bob的体重。

输出

输出一个整数,表示经过多少年后Limak将会比Bob重。

分析

初看的话,很容易就想到通过循环试数,即对于Limak,year = n年后,他的重量是a×3n,而Bob则为b×2n。只需当Limak体重严格大于Bob后跳出循环,并输出year。
    这里换一种思路,不通过循环试数,而是直接输出结果。
    对于已知判断结果公式(1 ≤ a ≤ b ≤ 10):
a×3n>b×2na×3^n > b ×2^na×3n>b×2n
    进行转换:
(32)n>ba(\frac{3}{2})^n > \frac{b}{a}(23​)n>ab​
    两边同取ln:
n×ln(32)>ln(ba)n×ln(\frac{3}{2}) >ln(\frac{b}{a})n×ln(23​)>ln(ab​)
    整理后:
n>ln(ba)ln(32)n>\frac{ln(\frac{b}{a})}{ln(\frac{3}{2})}n>ln(23​)ln(ab​)​
    由上述可知不等于右边结果应该为double类型,又按本题要求,需严格大于他的兄弟Bob,因此对于等式右边的数可以进行类型强转,从double转为int,使得该数忽略掉小数部分,再+1,即为最终结果。

代码

直接输出结果的写法:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{double a, b;//定义成double类型cin >> a >> b;cout << (int)(log(b / a) / log(1.5)+1);/*这里不能写3/2,会被认为是int型,而导致除数为ln(1)=0*/return 0;
}

循环试数:

#include<iostream>
#include<cmath>
using namespace std;
int main()
{int a, b;int year = 0;cin >> a >> b;while (1){if (a * pow(3, year) > b * pow(2, year))break;year++;}cout << year;return 0;
}

791A.Bear and Big Brother相关推荐

  1. CF - 791A. Bear and Big Brother - 模拟

    1.题目描述: A. Bear and Big Brother time limit per test 1 second memory limit per test 256 megabytes inp ...

  2. Codeforces——791A Bear and Big Brother

    小声BB 又开始更新了,最近打游戏王DL,这个栏目会留一些上分的心得. 题干 time limit per test:1 second memory limit per test:256 megaby ...

  3. Bear and Big Brother

    文章目录 一.Bear and Big Brother 总结 一.Bear and Big Brother 本题链接:Bear and Big Brother 题目: A. Bear and Big ...

  4. Codeforces A. Bear and Big Brother

    ...不行.这题之后.不做1000分以下的了.很耻辱 A. Bear and Big Brother time limit per test 1 second memory limit per tes ...

  5. 【codeforces 791A】Bear and Big Brother

    [题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...

  6. A. Bear and Big Brother

    还是水题,上代码 #include <cstdio> #include <cstring> #include <algorithm> #include <bi ...

  7. Codeforces Bear and Big Brother

    题目链接 题目意思 现在有两头熊,分别为熊大,熊二.他们的体重分别为a,b,其中a<=b.熊大每年体重增加三倍,熊二每年体重增加两倍.现在问过几年熊大的体重比熊二重. 解题思路 这就是一道简单的 ...

  8. CF791A Bear and Big Brother 【题解】

    来一篇O(1)O(1)O(1)的题解 题目可以转化为求最小的xxx使得下式成立. a∗3x>b∗2xa*3^x>b*2^xa∗3x>b∗2x 继续转化 3x2x>ba\frac ...

  9. Codeforces上通过数超过5W人的题

    Codeforces上通过数超过5W人的题 共32题:1000分4题,800分28题. 编号 题号 题名 分数 通过数 1 4A Watermelon 800 x193501 2 71A Way To ...

  10. Code Forces Bear and Forgotten Tree 3 639B

    B. Bear and Forgotten Tree 3 time limit per test2 seconds memory limit per test256 megabytes inputst ...

最新文章

  1. %3c- r语言运算符,R语言基础教程之运算符
  2. 什么叫做石英表_石英表和机械表的区别是什么
  3. 注意力机制可视化_目标跟踪中的(STAM)时空注意力机制
  4. 针对Hybrid A*论文解析(5)中的方法的一些验证
  5. Spring MVC 起步
  6. 【手把手】教你MySQL调优
  7. android字体右对齐,Android TextView将文本右对齐和左对齐
  8. 重磅!景驰科技公司CTO Tony Han加入硅谷科技论坛!
  9. GE PLC的EGD协议通信
  10. 按键精灵移动端系列 - IOS(苹果版)安装1.3.8 deb
  11. Gvim开发环境配置笔记--Windows篇(转)
  12. unity中content size fitter组件不起作用
  13. 应用包含Involution算子的RedNet实现Classification
  14. CTU-UHB Intrapartum Cardiotocography Database 产时CTG信号数据下载与读取(2021.7.9 新增阿里云盘下载)
  15. Google的地理信息反向编码结果中的字段说明
  16. 崔莺莺到宋楚瑜,张你怎么看待?
  17. SpringBoot 整合实现RabbitMQ
  18. 数字图像处理100问—33 傅立叶变换——低通滤波
  19. Rose HA双机热备出现问题及解决方法
  20. 【算法】树状数组 P1908 逆序对

热门文章

  1. 华为路由器命令行PPPOE拨号案例
  2. java游戏代码大全_求一个简单的Java小游戏的代码
  3. php匹配ubb,php创建属于自己的UBB代码
  4. 在CSDN的第0篇博客
  5. 2022年最新版黑马程序员Java自学路线(免费分享)
  6. C语言函数调用的方式求两个数的大小
  7. 用bat命令重启explorer的方法
  8. 没有灵魂的微信小程序代码转支付宝小程序代码
  9. [Unity插件]Live2D插件学习
  10. 区块链技术指南之分布式的一致性