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;
    }
    
  • 相关阅读:
    Pytorch笔记 (2) 初识Pytorch
    Pytorch笔记 (1) 初始神经网络
    c++ 数据抽象 、封装 接口(抽象类)
    c++ 多态
    c++ 重载运算符和重载函数
    c++ 继承
    c++面向对象 —— 类和对象
    c++ 结构
    c++ 基本的输入输出
    c++ 引用 日期&时间
  • 原文地址:https://www.cnblogs.com/mmlz/p/5873690.html
Copyright © 2011-2022 走看看