791A.Bear and Big Brother
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相关推荐
- 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 ...
- Codeforces——791A Bear and Big Brother
小声BB 又开始更新了,最近打游戏王DL,这个栏目会留一些上分的心得. 题干 time limit per test:1 second memory limit per test:256 megaby ...
- Bear and Big Brother
文章目录 一.Bear and Big Brother 总结 一.Bear and Big Brother 本题链接:Bear and Big Brother 题目: A. Bear and Big ...
- Codeforces A. Bear and Big Brother
...不行.这题之后.不做1000分以下的了.很耻辱 A. Bear and Big Brother time limit per test 1 second memory limit per tes ...
- 【codeforces 791A】Bear and Big Brother
[题目链接]:http://codeforces.com/contest/791/problem/A [题意] 给你两个数字a和b; a每次乘3,b每次乘2 问你什么时候a第一次大于b [题解] 傻逼 ...
- A. Bear and Big Brother
还是水题,上代码 #include <cstdio> #include <cstring> #include <algorithm> #include <bi ...
- Codeforces Bear and Big Brother
题目链接 题目意思 现在有两头熊,分别为熊大,熊二.他们的体重分别为a,b,其中a<=b.熊大每年体重增加三倍,熊二每年体重增加两倍.现在问过几年熊大的体重比熊二重. 解题思路 这就是一道简单的 ...
- 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 ...
- Codeforces上通过数超过5W人的题
Codeforces上通过数超过5W人的题 共32题:1000分4题,800分28题. 编号 题号 题名 分数 通过数 1 4A Watermelon 800 x193501 2 71A Way To ...
- 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 ...
最新文章
- %3c- r语言运算符,R语言基础教程之运算符
- 什么叫做石英表_石英表和机械表的区别是什么
- 注意力机制可视化_目标跟踪中的(STAM)时空注意力机制
- 针对Hybrid A*论文解析(5)中的方法的一些验证
- Spring MVC 起步
- 【手把手】教你MySQL调优
- android字体右对齐,Android TextView将文本右对齐和左对齐
- 重磅!景驰科技公司CTO Tony Han加入硅谷科技论坛!
- GE PLC的EGD协议通信
- 按键精灵移动端系列 - IOS(苹果版)安装1.3.8 deb
- Gvim开发环境配置笔记--Windows篇(转)
- unity中content size fitter组件不起作用
- 应用包含Involution算子的RedNet实现Classification
- CTU-UHB Intrapartum Cardiotocography Database 产时CTG信号数据下载与读取(2021.7.9 新增阿里云盘下载)
- Google的地理信息反向编码结果中的字段说明
- 崔莺莺到宋楚瑜,张你怎么看待?
- SpringBoot 整合实现RabbitMQ
- 数字图像处理100问—33 傅立叶变换——低通滤波
- Rose HA双机热备出现问题及解决方法
- 【算法】树状数组 P1908 逆序对