zoukankan      html  css  js  c++  java
  • codeforces 712C C. Memory and De-Evolution(贪心)

    题目链接:

    C. Memory and De-Evolution

    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.

    In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.

    What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?

    Input

    The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.

    Output

    Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.

    Examples
    input
    6 3
    output
    4
    input
    8 5
    output
    3
    input
    22 4
    output
    6

    题意:

    把变成为x的等边三角形变成边长为y的三角形,其中过程要求三角形恒成立,最少需要操作多少次;

    思路:

    反过来贪心;

    AC代码:

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    #include <cmath>
    #include <bits/stdc++.h>
    #include <stack>
    #include <map>
      
    using namespace std;
      
    #define For(i,j,n) for(int i=j;i<=n;i++)
    #define mst(ss,b) memset(ss,b,sizeof(ss));
      
    typedef  long long LL;
      
    template<class T> void read(T&num) {
        char CH; bool F=false;
        for(CH=getchar();CH<'0'||CH>'9';F= CH=='-',CH=getchar());
        for(num=0;CH>='0'&&CH<='9';num=num*10+CH-'0',CH=getchar());
        F && (num=-num);
    }
    int stk[70], tp;
    template<class T> inline void print(T p) {
        if(!p) { puts("0"); return; }
        while(p) stk[++ tp] = p%10, p/=10;
        while(tp) putchar(stk[tp--] + '0');
        putchar('
    ');
    }
      
    const int mod=1e9+7;
    const double PI=acos(-1.0);
    const LL inf=1e18;
    const int N=(1<<20)+10;
    const int maxn=1e5+110;
    const double eps=1e-12;
     
    
    int x,y;
    queue<int>qu;
    int main()
    {
        read(x);read(y);
        int ans=0;
        qu.push(y);qu.push(y);qu.push(y);
        while(1)
        {
            int f=qu.front();qu.pop();
            int g=qu.front();qu.pop();
            int u=qu.front();qu.pop();
            if(f>=x&&g>=x&&u>=x)break;
            ans++;
            qu.push(g);qu.push(u);qu.push(g+u-1);
        }
        cout<<ans<<endl;
        return 0;
    }
    

      

  • 相关阅读:
    git问题记录
    @Slf4j注解
    idea修改maven项目名
    spring的定时任务schedule
    @RequestParam详解
    统一全局异常处理将出错的栈信息打印到日志中
    python交互环境中导入文件中自定义的函数报错
    关于服务器的小技巧
    Python学习
    前后端分离时,获取不到session
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5876913.html
Copyright © 2011-2022 走看看