zoukankan      html  css  js  c++  java
  • Codeforces 712C Memory and De-Evolution

    Description

    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  le  y < x  le 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).

    Sample Input

    22 4

    Sample Ouput

    6

    我还是too old了。怎么都没想出正的怎么贪心,改了1.5h。TM正解居然是逆向思考,从(y)(x),最佳的方法肯定是用边界三角形来每次更新一条边((a = b+c-1)),这样子轮流更新三角形变大最快,以此来贪心。
    代码如下:

    #include<iostream>
    #include<cstdio>
    #include<cstdlib>
    using namespace std;
    
    int aim,l[3],res = 3,ans;
    
    int main()
    {
    	freopen("C.in","r",stdin);
    	freopen("C.out","w",stdout);
    	scanf("%d %d",&aim,&l[0]); l[1] = l[2] = l[0];
    	while (res)
    	{
    		for (int i = 0;i < 3&&res;++i)
    		{
    			l[i] = l[(i+1)%3]+l[(i+2)%3]-1; ++ans;
    			if (l[i] >= aim) --res,l[i] = aim;
    		}
    	}
    	printf("%d",ans);
    	fclose(stdin); fclose(stdout);
    	return 0;
    }
    
  • 相关阅读:
    解析3D打印切片软件:Cura
    步步为营,打造CQUI UI框架
    PHP为什么empty可以访问不存在的索引
    这是一篇关于魔法(Science)上网的教程
    【新阁教育】这样玩PLC,是不是有意思多了
    「新阁教育」西门子TIA实现BadApple完整实例
    C#数据结构-赫夫曼树
    C#数据结构-线索化二叉树
    SQL优化器-RBO与CBO分别是什么
    Linux下安装并配置VSCode(Visual Studio Code)
  • 原文地址:https://www.cnblogs.com/mmlz/p/5873690.html
Copyright © 2011-2022 走看看