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;
    }
    
  • 相关阅读:
    网宿科技股份有限公司投资者关系活动记录表(2014.3.30)
    网宿科技投资者关系活动记录2016年10月31日
    [转载]20131206 网宿科技电话交流会纪要
    strlcpy和strlcat
    114 的 dns 的解析测试
    大批量数据读写
    ART——一个轻量级的web报表工具
    递归删除.svn文件
    SA常用命令
    淘女郎团队敏捷开发实践2011上半年回顾
  • 原文地址:https://www.cnblogs.com/mmlz/p/5873690.html
Copyright © 2011-2022 走看看