参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6379014.html

【题目链接】

C. Memory and De-Evolution

time limit per test:2 seconds
memory limit per test:256 megabytes
input:standard input

output:standard output

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 ≤ y < x ≤ 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.

  • Examples
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6

  • Note

In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides ab, and c as (a, b, c). Then, Memory can do .

In the second sample test, Memory can do .

In the third sample test, Memory can do: 

.

【题意】

现有边长为x的等边三角形,Memory想要将其变成边长为y的等边三角形。

现规定Memory每秒能够改变一条边的大小,但要保证改变后的三条边仍能构成一个三角形。

问最少需要多少时间才能变为边长为y的等边三角形?

【分析】

从边长为6的等边三角形变为边长为3的等边三角形。先将一边变为3,则(6,6,3),如果再将一边变成3,则(6,3,3)并不能组成三角形,所以只能先变为(6,4,3)然后变为(3,4,3),最后变为(3,3,3),一共4步,所以输出4,此题很明显是贪心,直接贪就是了,用一个数记录需要的时间即可!此题需要注意的是最好选择逆推法,由y->x,这样就能保证合法且最快了!

【时间复杂度】O(n)

借鉴于:HERE


【代码实现】

#include<stdio.h>
int main(){int s[3];int x,y,i;while(1){scanf("%d%d",&x,&y);s[0]=s[1]=s[2]=y;for(i=0; s[0]<x||s[1]<x||s[2]<x; i++)s[i%3]=s[(i+1)%3]+s[(i+2)%3]-1;printf("%d\n",i);}return 0;
} 

转载于:https://www.cnblogs.com/fangxiaoqi/p/10200942.html

Codeforces 712C Memory and De-Evolution相关推荐

  1. Codeforces 712C. Memory and De-Evolution

    题目链接:http://codeforces.com/problemset/problem/712/C 题意: 给你两个值 a 和 b (a > b), 代表这里有两个等边三角形, 边长分别为 ...

  2. Codeforces 712E Memory and Casinos

    Description There are n casinos lined in a row. If Memory plays at casino \(i\), he has probability ...

  3. Codeforces 712A. Memory and Crow

    题目链接:http://codeforces.com/problemset/problem/712/A 题意: 有两个序列 ai 和 bi, 长度都为 n, 对于序列 ai 满足 ai = bi - ...

  4. Codeforces 712A Memory and Crow

    参考自:https://www.cnblogs.com/ECJTUACM-873284962/p/6374955.html [题目链接]  A. Memory and Crow time limit ...

  5. codeforces A. Memory and Crow

    A. Memory and Crow time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

  6. codeforces 712 Memory and De-Evolution

    2019-05-19 13:25:37 加油,加油,坚持,坚持!!! 一定要逆推,才可以是最少的次数 更好的方法: https://www.cnblogs.com/ECJTUACM-873284962 ...

  7. ECJTUACM16 Winter vacation training #4 题解源码

    https://vjudge.net/contest/149692#overview 这周一VJ比赛,题解&源码已完成! A.................................. ...

  8. c/c++动态检测内存错误利器 - ASan

    ASan,即Address Sanitizer,是一个适用于c/c++的动态内存错误检测器,它由一个编译器检测模块(LLVM pass)和一个替换malloc函数的运行时库组成,在性能及检测内存错误方 ...

  9. 耶鲁大学开放课程:《心理学导论》

    课程类型:心理学 课程介绍: 你的梦应该如何解析?男人和女人在两性需求的性质和程度是否不同?猩猩能否学习手语?为什么我们不能 胳肢自己?本课程试图回答这些以及其他诸如此类的问题,并提供了思想和行为科学 ...

  10. Codeforces Round #370 (Div. 2) A. Memory and Crow 水题

    A. Memory and Crow 题目连接: http://codeforces.com/contest/712/problem/A Description There are n integer ...

最新文章

  1. 17个提升iOS开发效率的神器
  2. [转帖]虚拟内存探究 -- 第二篇:Python 字节
  3. 【BZOJ】3779 重组病毒
  4. centos7杀掉进程_Linux下强制杀死进程的方法详解
  5. 输入圆的半径,计算并输出圆的周长和面积
  6. echarts自学笔记
  7. node.js打包环境部署CentOS7.4
  8. 7-130 古风排版 (20 分)
  9. Java Servlet cookie
  10. 《美团机器学习实践》—— 读后总结
  11. Web服务器之Http压缩(GZip)
  12. 英文名称(缩写)汇总
  13. 基于多任务深度学习的时空网络流量预测
  14. java 调错_Java FX Rubberband调整大小错误
  15. 使用C# 开发Pocket PC 应用程序(转)
  16. linux+unlock+10,unlock解锁工具 - 亚风软件站
  17. Python金融科技:cufflinks绘制金融图表
  18. mysql投影和选择区别_关系运算里面,“选择”和“投影”区分?
  19. 学堂在线数据结构-chap2
  20. SAN存储和服务器虚拟化安装方案,如何部署SAN

热门文章

  1. Sql Server 日期格式化函数
  2. 我最看不惯的几个公众号
  3. 超有趣的灵魂都在看什么?
  4. 逻辑斯蒂回归:家庭买私家车的概率
  5. mariadb修改默认字符集
  6. Java反射之修改常量值
  7. 求数组子序列和最大值
  8. jquery中常见的标题内容之间的切换
  9. Problem 1108 - 淼·诺贝尔
  10. 技术要求→物理安全→防雷击