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;
}

Codeforces 712C Memory and De-Evolution的更多相关文章

  1. CodeForces 712C Memory and De-Evolution (贪心+暴力)

    题意:现在有一个长度为 x 的正三角形,每次可以把一条边减小,然后用最少的时间变成长度为 y 的正三角形. 析:一开始,正着想,然后有一个问题,就是第一次减小多少才能最快呢?这个好像并不好确定,然后我 ...

  2. codeforces 712C C. Memory and De-Evolution(贪心)

    题目链接:http://codeforces.com/problemset/problem/712/C 题目大意: 给连个值x,y (3 ≤ y < x ≤ 100 000), x,y都为等边三 ...

  3. codeforces 712B. Memory and Trident

    题目链接:http://codeforces.com/problemset/problem/712/B 题目大意: 给出一个字符串(由'U''D''L''R'),分别是向上.向下.向左.向右一个单位, ...

  4. codeforces 712A. Memory and Crow

    题目链接:http://codeforces.com/problemset/problem/712/A 题目大意: 给你一个数字系列,求其满足条件的一个序列. 条件为: ai = bi - bi +  ...

  5. Codeforces 712E Memory and Casinos

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

  6. CodeForces 712B Memory and Trident (水题,暴力)

    题意:给定一个序列表示飞机要向哪个方向飞一个单位,让你改最少的方向,使得回到原点. 析:一个很简单的题,把最后的位置记录一下,然后要改的就是横坐标和纵坐标绝对值之和的一半. 代码如下: #pragma ...

  7. CodeForces 712A Memory and Crow (水题)

    题意:有一个序列,然后对每一个进行ai = bi - bi + 1 + bi + 2 - bi + 3.... 的操作,最后得到了a 序列,给定 a 序列,求原序列. 析:很容易看出来,bi = ai ...

  8. [CodeForces - 712D]Memory and Scores (DP 或者 生成函数)

    题目大意: 两个人玩取数游戏,第一个人分数一开始是a,第二个分数一开始是b,接下来t轮,每轮两人都选择一个[-k,k]范围内的整数,加到自己的分数里,求有多少种情况使得t轮结束后a的分数比b高.  ( ...

  9. CodeForces 712D Memory and Scores

    $dp$,前缀和. 记$dp[i][j]$表示$i$轮结束之后,两人差值为$j$的方案数. 转移很容易想到,但是转移的复杂度是$O(2*k)$的,需要优化,观察一下可以发现可以用过前缀和来优化. 我把 ...

随机推荐

  1. qt 与mysql建立交互式连接

    void QSqlDatabase::setConnectOptions(const QString & options = QString())Sets database-specific ...

  2. OC学习笔记[注意事项]

    alloc  new  retain之后都必须要调用release方法 计数器要变只有这几种方法 retain release alloc new copy方法才会使计数器改变,谁想用人家对象,就对他 ...

  3. Java 授权内幕--转载

    在信息安全性领域,授权是世界的的中心,因为它是控制个体(即人.进程和计算机)对系统资源的访问权限的过程.直到最近,在 Java 安全体系结构中相关的问题都是“这段运行中的代码的访问权限是什么?” 随着 ...

  4. Freemarker学习中遇到的问题

    在网上找到了尚学堂的视频,同时有书和源码等资料.但是在跟着练习的过程中,代码运行报了错: 2015-7-20 22:26:40 freemarker.log.JDK14LoggerFactory$JD ...

  5. .NET 解析HTML代码——NSoup

    NSoup是一个开源框架,是JSoup(Java)的.NET移植版本 1.直接用起来 NSoup.Nodes.Document htmlDoc = NSoup.NSoupClient.Parse(HT ...

  6. 使用Socket模拟一个简单的Webservice调用

    webservice是对socket的一个封装,让远程调用调用变得更加简单,那么使用socket究竟有多么麻烦呢?来看看. 做一个简单的天气查询: 服务端: public class SocketSe ...

  7. android打包签名介绍

    Keytool 是一个有效的安全钥匙和证书的管理工具. Java 中的 keytool.exe (位于 JDK\Bin 目录下)可以用来创建数字证书,所有的数字证书是以一条一条(采用别名区别)的形式存 ...

  8. iOS常见的几种延时执行的方法

    1.performSelector [self performSelector:@selector(delayMethod) withObject:nil/*可传任意类型参数*/ afterDelay ...

  9. spring jar包、文档官网下载

    一.spring的官方网址:http://spring.io/ 二.看到这个简洁清新的界面,导航很明确,进入projects whatever the infrastructure needs of ...

  10. 用Eclipse+xdebug调试PHP总是在首行自动断点解决方法

    问题描述: 使用Eclipse+PDT+xdebug调试PHP程序时,总是在程序的第一行(首行)自动断点,不方便调试. 解决方法: 分别在下面3个位置配置,取消 Break at First Line ...