zoukankan      html  css  js  c++  java
  • 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("0
    ");
    12             else if(a-b==0)
    13                 printf("1
    ");
    14         while(a-b<0)
    15         {
    16             ans++;
    17             a*=3;
    18             b*=2;
    19             if(a-b>0)
    20             {
    21                 printf("%d
    ",ans);
    22                 break;
    23             }
    24             else if(a-b==0)
    25             {
    26                 printf("%d
    ",ans+1);
    27                 break;
    28             }
    29         }
    30     }
    31     return 0;
    32 }
  • 相关阅读:
    Json schema前奏 关于JSON
    笔试题:能被1~10同时整除的最小整数是2520,问能被1~20同时整除的最小整数是多少?
    CentOS7 安装 Docker、最佳Docker学习文档
    2019年4399暑期实习算法题2,迷宫路径条数
    2019vivo秋招提前批笔试题第3题
    python内存机制与垃圾回收、调优手段
    N皇后问题的python实现
    一行代码判断一个数是否是2的整数次方
    在O(1)的时间内删除链表节点
    打印从1到n位数的最大值
  • 原文地址:https://www.cnblogs.com/ECJTUACM-873284962/p/6596694.html
Copyright © 2011-2022 走看看