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;
    }
    
  • 相关阅读:
    nginx解决跨域问题
    SSM整合相关试题
    SSM整合案例--用户登录
    非法用户登录拦截
    SpringMVC拦截器和数据校验
    SpringMVC文件上传
    SpringMVC异常处理
    SpringMVC方法的返回值类型和自动装配
    SpringMVC
    spring和mybatis整合
  • 原文地址:https://www.cnblogs.com/mmlz/p/5873690.html
Copyright © 2011-2022 走看看