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;
    }
    

      

  • 相关阅读:
    sql语句之case when null 解决方法
    sql server分组按顺序编号(转+补充)
    非IE用window.open弹出窗口并向父窗口传值
    IE6浏览器弹出窗口,父窗口传值
    sql之储存过程与函数的区别
    sql之执行事务性语句
    c#获取与筛选对象相匹配的所有DataRow对象数组
    ?: 运算符(C# 参考)
    Mysql 5.7优化
    libcurl.a 跨平台
  • 原文地址:https://www.cnblogs.com/zhangchengc919/p/5876913.html
Copyright © 2011-2022 走看看