• 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;
    }
    
  • 相关阅读:
    H264源码分析(四)
    矩阵在编程中的一个小应用
    android listview 三种适配器设置
    Android SoundPool 的使用以及原理分析
    poj 2728 Desert King(最优比例生成树)
    MySQL 查询结果以百分比显示
    Android Application
    飘逸的python
    CSS教程:div垂直居中的N种方法[转]
    HQL: Hibernate查询语言
  • 原文地址:https://www.cnblogs.com/mmlz/p/5873690.html
Copyright © 2020-2023  润新知