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 ≤ 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 a, b, 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:

.

题意:将一个大的等边三角形变为小的等边三角形,最小需要几步

解法:我们倒过来考虑要方便很多,先增加其中一条边到最大,然后增加第二条边,依次循环到大的等边三角形

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,m;
int a,b,c;
int pos;
int cot=0;
cin>>n>>m;
a=m,b=m,c=m;
while(a!=n||b!=n||c!=n)
{
if(a!=n)
{
int pos1;
//cout<<"A"<<endl;
for(int i=1; i<=n; i++)
{
// cout<<"B"<<endl;
// cout<<a<<" "<<b<<" "<<c<<endl;
if((a+i)+b>c&&(b+c)>(a+i)&&(a+i)+c>b&&(a+i)<=n)
{
pos1=i;
// cot++;
}
}
a=a+pos1;
cot++;
// cout<<a<<endl;
// break;
// cout<<a<<" "<<b<<" "<<c<<endl;
}
// cout<<a<<" "<<b<<" "<<c<<endl;
// break;
if(b!=n)
{
int pos2;
for(int i=1; i<=n; i++)
{
// cout<<"B"<<endl;
if((b+i)+a>c&&(a+c)>(b+i)&&(b+i)+c>a&&(b+i)<=n)
{
// b=b+i;
pos2=i;
//cot++;
}
}
b=b+pos2;
cot++;
// cout<<a<<" "<<b<<" "<<c<<endl;
}
// cout<<a<<" "<<b<<" "<<c<<endl;
// break;
if(c!=n)
{
int pos3;
for(int i=1; i<=n; i++)
{
if((c+i)+a>b&&b+(c+i)>a&&b+a>c+i&&(c+i)<=n)
{
// cout<<i<<endl;
pos3=i;
// c=c+i;
// cot++;
} } c=pos3+c;
cot++;
// cout<<a<<" "<<b<<" "<<c<<endl;
}
// break;
// cout<<a<<" "<<b<<" "<<c<<endl;*/
}
cout<<cot<<endl;
return 0;
}

  

Codeforces Round #370 (Div. 2) C的更多相关文章

  1. Codeforces Round #370 (Div. 2) E. Memory and Casinos (数学&&概率&&线段树)

    题目链接: http://codeforces.com/contest/712/problem/E 题目大意: 一条直线上有n格,在第i格有pi的可能性向右走一格,1-pi的可能性向左走一格,有2中操 ...

  2. Codeforces Round #370 (Div. 2) E. Memory and Casinos 线段树

    E. Memory and Casinos 题目连接: http://codeforces.com/contest/712/problem/E Description There are n casi ...

  3. Codeforces Round #370 (Div. 2)C. Memory and De-Evolution 贪心

    地址:http://codeforces.com/problemset/problem/712/C 题目: C. Memory and De-Evolution time limit per test ...

  4. Codeforces Round #370 (Div. 2)B. Memory and Trident

    地址:http://codeforces.com/problemset/problem/712/B 题目: B. Memory and Trident time limit per test 2 se ...

  5. Codeforces Round #370 (Div. 2) D. Memory and Scores 动态规划

    D. Memory and Scores 题目连接: http://codeforces.com/contest/712/problem/D Description Memory and his fr ...

  6. Codeforces Round #370 (Div. 2) C. Memory and De-Evolution 水题

    C. Memory and De-Evolution 题目连接: http://codeforces.com/contest/712/problem/C Description Memory is n ...

  7. Codeforces Round #370 (Div. 2) B. Memory and Trident 水题

    B. Memory and Trident 题目连接: http://codeforces.com/contest/712/problem/B Description Memory is perfor ...

  8. 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 ...

  9. Codeforces Round #370(div 2)

    A B C :=w= D:两个人得分互不影响很关键 一种是f[i][j]表示前i轮,分差为j的方案数 明显有f[i][j]=f[i-1][j-2k]+2*f[i-1][j-2k+1]+...+(2k+ ...

  10. Codeforces Round #370 (Div. 2)(简单逻辑,比较水)

    C. Memory and De-Evolution time limit per test 2 seconds memory limit per test 256 megabytes input s ...

随机推荐

  1. [原创]java WEB学习笔记53:Struts2学习之路---前奏:使用 Filter 作为控制器的 MVC

    本博客的目的:①总结自己的学习过程,相当于学习笔记 ②将自己的经验分享给大家,相互学习,互相交流,不可商用 内容难免出现问题,欢迎指正,交流,探讨,可以留言,也可以通过以下方式联系. 本人互联网技术爱 ...

  2. struts自定义拦截器

    第01步:配置web.xml,启动struts框架 <?xml version="1.0" encoding="UTF-8"?> <web-a ...

  3. 使用UIL(Universal-Image-Loader)异步加载图片

    概要: Android-Universal-Image-Loader是一个开源的UI组件程序,该项目的目的是实现可重复使用的异步图像加载.缓存和显示.所以,如果你的程序里需要这个功能的话,使用它,因为 ...

  4. 关于 VS 无法转到定义和无法转到使用的问题

    今天提交完代码以后突然发现  咦  怎么F12 .点击右键的方法都不能转到定义了    转到引用 也提示  没有发现   重启VS  还是不行 .去找王晓  他也不清楚(其实我知道 他应该也不清楚  ...

  5. 阿里 drds 分布式数据库分节点查询

    mybatis 模式下,xml 中写法 <select id="selectFailDetailOneNode" resultMap="BaseResultMap& ...

  6. 夺命雷公狗ThinkPHP项目之----企业网站18之网站配置列表页的完成

    我们点击下配置列表即可查看我们列表页的配置信息了: 其实这个最简单了,首先我们先来完成他控制器的代码: public function lists(){ $mod = M('Conf')->se ...

  7. wc移植sae笔记

    1.wc移植到sae---上传图片 ①先看profile.ptl.html中的ajax代码修改functions.js中G_BASE_URL的值.在这里我先写死成->'http://2.idan ...

  8. 《OpenGL游戏编程》第9章-PlanarShadow关键代码注释

    阴影这块确实是难点.说到阴影就必须提到投影矩阵.模板值为1和2时分别渲染.说来话长,仅仅放上代码,供日后查阅. /** 渲染墙面和阴影 */ void CPlanarShadow::Render() ...

  9. 关于oracle 11g 64位与 32位的 plsql、及其他32位应用程序共存的问题

    因为 plsql 不支持 64位 oracle 客户端,所以plsql 必须使用 oracle 的 32位 instanclient 包.  解压缩后放一个目录,例如: D:\Oracle\insta ...

  10. 五分钟打造自己的sql性能分析工具

    1.首先要有一个trace文件 2. 打开trace文件 3. 另存为跟踪表 4.登录你要保存到的目标sqlserver服务器 5. 选择要保存的数据库和表名称 6. 保存完成(左下角出现进度直到显示 ...