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. cordova3.X 运用grunt生成plugin自定义插件骨架

    Cordova提供了一组设备相关的API,通过这组API,移动应用能够以JavaScript访问原生的设备功能,如摄像头.麦克风等.Cordova还提供了一组统一的JavaScript类库,以及为这些 ...

  2. windows系统调用 进程快照

    #include "windows.h" #include "tlhelp32.h" #include "iostream" using n ...

  3. Android -- 自定义View小Demo,关于Path类的使用(一)

    1,在我们知道自定义view中onDraw()方法是用于绘制图形的,而Path类则是其中的一个重要的类,如下图效果: 代码也没有什么难度,直接贴出来吧 @Override protected void ...

  4. SparkSQL基础应用(1.3.1)

    一.概述 从1.3版本开始Spark SQL不再是测试版本,之前使用的SchemaRDD重命名为DataFrame,统一了Java和ScalaAPI. SparkSQL是Spark框架中处理结构化数据 ...

  5. 用WIN7系统IIS的提示:数据库连接出错,请检查Conn.asp文件中的数据库参数设置

    我用科讯的从4.0开始,去年开始很少用科讯做新站了,今天拿来做一下,结果悲剧了,数据库路径老是不对,百度一番又一番的,,最后终于给度娘解决了.分享出来给遇到同样的问题的人. 用WIN7系统IIS的注意 ...

  6. Oracle重置序列(不删除重建方式)

    Oracle中一般将自增sequence重置为初始1时,都是删除再重建,这种方式有很多弊端,依赖它的函数和存储过程将失效,需要重新编译. 不过还有种巧妙的方式,不用删除,利用步长参数,先查出seque ...

  7. RobotFramework 安装配置(二)

    前面已经写了一篇关于RF的安装配置了,那是在做自动化工具调研的时候搭建RF总结的,基于win32的系列软件安装的过程.经过1个月的调研,做成了demo,也大致学RF的使用和python的基础语法,暂时 ...

  8. yum源的修改

    源路径: /etc/yum.repos.d/ 配置文件: 网络搜索 CentOS-Base.repo(默认) 设备搜索 CentOS-Media.repo 将CentOS-Base.repo移除或改名 ...

  9. scala匿名函数

    package com.ming.test import scala.math._ object AnonymousFunc { def valueAtOneQuarter(f:(Double)=&g ...

  10. 一篇文章一张思维导图看懂Android学习最佳路线

    一篇文章一张思维导图看懂Android学习最佳路线 先上一张android开发知识点学习路线图思维导图 Android学习路线从4个阶段来对Android的学习过程做一个全面的分析:Android初级 ...