Codeforces 791A Bear and Big Brother(暴力枚举,模拟)
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?
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.
Print one integer, denoting the integer number of years after which Limak will become strictly larger than Bob.
4 7
2
4 9
3
1 1
1
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代码:
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a,b,i;
int c,d;
while(scanf("%d%d",&a,&b)!=EOF)
{
int ans=;
if(a-b>)
printf("0\n");
else if(a-b==)
printf("1\n");
while(a-b<)
{
ans++;
a*=;
b*=;
if(a-b>)
{
printf("%d\n",ans);
break;
}
else if(a-b==)
{
printf("%d\n",ans+);
break;
}
}
}
return ;
}
Codeforces 791A Bear and Big Brother(暴力枚举,模拟)的更多相关文章
- Codeforces 425A Sereja and Swaps(暴力枚举)
题目链接:A. Sereja and Swaps 题意:给定一个序列,能够交换k次,问交换完后的子序列最大值的最大值是多少 思路:暴力枚举每一个区间,然后每一个区间[l,r]之内的值先存在优先队列内, ...
- Codeforces Round #253 (Div. 2)B(暴力枚举)
就暴力枚举所有起点和终点就行了. 我做这题时想的太多了,最简单的暴力枚举起始点却没想到...应该先想最简单的方法,层层深入. #include<iostream> #include< ...
- Codeforces A. Bear and Big Brother
...不行.这题之后.不做1000分以下的了.很耻辱 A. Bear and Big Brother time limit per test 1 second memory limit per t ...
- codeforces 869A The Artful Expedient【暴力枚举/亦或性质】
A. time limit per test 1 second memory limit per test 256 megabytes input standard input output stan ...
- Codeforce 791A - Bear and Big Brother
Bear Limak wants to become the largest of bears, or at least to become larger than his brother Bob. ...
- Codeforces 653C Bear and Up-Down【暴力】
题目链接: http://codeforces.com/problemset/problem/653/C 题意: 给定序列,偶数位的数字比两边都大,则成为nice,只可以交换两个数字,问有多少种交换方 ...
- Codeforces Round #258 (Div. 2)C(暴力枚举)
就枚举四种情况,哪种能行就是yes了.很简单,关键是写法,我写的又丑又长...看了zhanyl的写法顿时心生敬佩.写的干净利落,简直美如画...这是功力的体现! 以下是zhanyl的写法,转载在此以供 ...
- CodeForces 550B Preparing Olympiad(DFS回溯+暴力枚举)
[题目链接]:click here~~ [题目大意] 一组题目的数目(n<=15),每一个题目有对应的难度,问你选择一定的题目(大于r个且小于l个)且选择后的题目里最小难度与最大难度差不小于x, ...
- HDU 4930 Fighting the Landlords(暴力枚举+模拟)
HDU 4930 Fighting the Landlords 题目链接 题意:就是题中那几种牌型.假设先手能一步走完.或者一步让后手无法管上,就赢 思路:先枚举出两个人全部可能的牌型的最大值.然后再 ...
随机推荐
- 【java】对象克隆protected Object clone() throws CloneNotSupportedException
package 对象克隆; class A implements Cloneable{//要具备clone()功能必须要实现Cloneable接口,此接口里无方法,只起标识作用. private St ...
- 结构体struct sockaddr_in, struct sockaddr,struct in_addr
一.结构体 struct sockaddr_in, struct sockaddr, struct in_addr struct sockaddr_in, struct sockaddr,str ...
- 前端构建之gulp与常用插件(转载)
原博主:幻天芒 原文地址:http://www.cnblogs.com/humin/p/4337442.html gulp是什么? http://gulpjs.com/ 相信你会明白的! 与著名的构建 ...
- c#$用法
为什么会出现$符号,c#6.0才出现的新特性 var s = string.Fromat("{0}+{1}={2}",12,23,12+23) 用起来必须输入string.From ...
- js 变量、作用域和内存问题
基本类型和引用类型 5种基本类型:undefined.null.boolean.number.string 引用类型:由多个值构成的对象 属性 引用类型可以动态添加属性,而基本类型不可以 var p ...
- 初识QT
前言:这是写给纯小白看的文章,大神可以自行绕道. QT的优势(摘自360百科): Qt支持下列操作系统: Microsoft Windows 95/98, Microsoft Windows NT, ...
- springBoot系列教程08:拦截器(Interceptor)的使用
拦截器intercprot 和 过滤器 Filter 其实作用类似 在最开始接触java 使用struts2的时候,里面都是filter 后来springmvc时就用interceptor 没太在意 ...
- thinkphp3.2.3的使用心得(零)
从模板传参到控制器 模板中代码: <volist name="list" id="vo"> <a href="__CONTROLLE ...
- 几种加密算法的java实现包括MD5、RSA、SHA256
SHA加密: package com; import java.security.MessageDigest;import java.security.NoSuchAlgorithmException ...
- 用C#实现微信“跳一跳”小游戏的自动跳跃助手
一.前言: 前段时间微信更新了新版本后,带来的一款H5小游戏“跳一跳”在各朋友圈里又火了起来,类似以前的“打飞机”游戏,这游戏玩法简单,但加上了积分排名功能后,却成了“装逼”的地方,于是很多人花钱花时 ...