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. XRDP与VNC的关系

    如果仅仅安装XRDP协议.是不能在windows上使用远程桌面连接到Ubuntu. 还须要安装VNCServer才行. 所以,XRDP启动之后.系统会自己主动启动一个VNC会话进程监听服务. 当我们通 ...

  2. Hrbust1328 相等的最小公倍数 (筛素数,素因子分解)

    本文出自:http://blog.csdn.net/svitter/ 题意: 求解An 与 An-1是否相等. n分为两个情况-- 1.n为素数, 2.n为合数. =  =好像说了个废话..素数的时候 ...

  3. mysql的优化措施,从sql优化做起

    http://geeksblog.cc/2016/06/11/mysql-optimize/ 优化sql的一般步骤 通过show status了解各种sql的执行频率 定位执行效率低的sql语句 通过 ...

  4. hadoop错误org.apache.hadoop.yarn.exceptions.YarnException Unauthorized request to start container

    错误: 14/04/29 02:45:07 INFO mapreduce.Job: Job job_1398704073313_0021 failed with state FAILED due to ...

  5. one problem about Apple Keychain in use

    解决方案 Add Security.framework, then rebuild. Sometimes I find I have to build clean and then rebuild. ...

  6. CCEditBox用法

    1.以下是CCEditBox的相关函数和类型说明: /* 编辑框的一些函数 setText("字符串"); //设置文本 setFontColor(color); //设置文本颜色 ...

  7. oracle合并查询

    1). Union 该操作符用于取得两个结果集的并集.当使用该操作符时,会自动去掉结果集中重复行. 2).union all 该操作符与union相似,但是它不会取消重复行,而且不会排序. 3). I ...

  8. Java基础知识强化之集合框架笔记56:Map集合之HashMap集合(HashMap<String,Student>)的案例

    1. HashMap集合(HashMap<String,Student>)的案例 HashMap是最常用的Map集合,它的键值对在存储时要根据键的哈希码来确定值放在哪里. HashMap的 ...

  9. C# 日期之间的间隔

    今天工作中,突然遇到要计算两个时间之间的天数,最后把自己的方法记录下来,其实挺简单的: DateTime dt1=Convert.ToDateTime("2014/8/1 23:53:31& ...

  10. Js 上传文件 页面不刷新

    html控件代码: <form id="form1"> <p><input type="file" name="mfil ...