Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
A. Bear and Big Brother
time limit per test:1 second
memory limit per test:256 megabytes
input:standard input
output:standard output
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob.
Right now, Limak and Bob weigh a and b respectively. It's guaranteed that Limak's weight is smaller than or equal to his brother's weight.
Limak eats a lot and his weight is tripled after every year, while Bob's weight is doubled after every year.
After how many full years will Limak become strictly larger (strictly heavier) than Bob?
Input
The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10) — the weight of Limak and the weight of Bob respectively.
Output
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
Examples
Input
4 7
Output
2
Input
4 9
Output
3
Input
1 1
Output
1
Note
In the first sample, Limak weighs 4 and Bob weighs 7 initially. After one year their weights are 4·3 = 12 and 7·2 = 14 respectively (one weight is tripled while the other one is doubled). Limak isn't larger than Bob yet. After the second year weights are 36 and 28, so the first weight is greater than the second one. Limak became larger than Bob after two years so you should print 2.
In the second sample, Limak's and Bob's weights in next years are: 12 and 18, then 36 and 36, and finally 108 and 72 (after three years). The answer is 3. Remember that Limak wants to be larger than Bob and he won't be satisfied with equal weights.
In the third sample, Limak becomes larger than Bob after the first year. Their weights will be 3 and 2 then.
分析:给你两个数字a和b; a每次乘3,b每次乘2,问你什么时候a第一次大于b!
题目链接:http://codeforces.com/contest/791/problem/A
下面给出AC代码:
1 #include <bits/stdc++.h>
2 using namespace std;
3 int main()
4 {
5 int a,b,i;
6 int c,d;
7 while(scanf("%d%d",&a,&b)!=EOF)
8 {
9 int ans=0;
10 if(a-b>0)
11 printf("0n");
12 else if(a-b==0)
13 printf("1n");
14 while(a-b<0)
15 {
16 ans++;
17 a*=3;
18 b*=2;
19 if(a-b>0)
20 {
21 printf("%dn",ans);
22 break;
23 }
24 else if(a-b==0)
25 {
26 printf("%dn",ans+1);
27 break;
28 }
29 }
30 }
31 return 0;
32 }
- WCF如何克服HTTP传输协议的局限提供对不同消息传输模式的实现
- H5手游大事件:腾讯上线“微信小游戏”!支持群分享与内购
- 我所理解的Remoting(2):远程对象生命周期的管理[上篇]
- 谈谈分布式事务(Distributed Transaction)[共5篇]
- SQLXML初体验:用XML代替T-SQL来操作数据库
- 自己动手写可视化软件(代码已开源)
- 探秘Tomcat——连接篇
- 微信小游戏正式上线,H5游戏迎新机遇
- WCF技术剖析之三十:一个很有用的WCF调用编程技巧[上篇]
- WCF技术剖析之十八:消息契约(Message Contract)和基于消息契约的序列化
- WCF技术剖析之三十:一个很有用的WCF调用编程技巧[上篇]
- 成为更好程序员的8种途径
- 探秘Tomcat——启动篇
- ai量化系统架构的思考
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 不要在Spring单元测试中使用 @Transactional注解
- OpenCV DNN模块官方教程(一)加载Caffe模型做图像分类
- Python爬虫之mongodb的聚合操作
- Linux中文输入法-搜狗输入法安装方法
- oracle 数据库问题:"ORA-01922: 必须指定 CASCADE 以删除...",原因及解决办法
- OpenCV DNN模块官方教程(二)YoloV4目标检测实例
- Python爬虫之mongodb的增删改查
- 恕我直言你可能真的不会java第2篇:Java Stream API?
- Python爬虫之mongodb的简单使用
- Java之美-死锁
- 恕我直言你可能真的不会java第4篇:Stream管道流Map操作
- 高工也要补基础,wait,notify,join
- 恕我直言你可能真的不会java第5篇:Stream的状态与并行操作
- 恕我直言你可能真的不会java第3篇:Stream的Filter与谓词逻辑
- 恕我直言你可能真的不会java第1篇:lambda表达式会用了么?