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. 查看linux [Fedora] 系统信息

    系统版本: $ /etc/issue Fedora release (Heisenbug)或者$ cat /etc/issue 系统位数: $ getconf LONG_BIT64 内核信息: $ c ...

  2. Java基础(36):String与基本数据类型之间的双向转换(Wrapper类)

    Java 中基本类型和字符串之间的转换 在程序开发中,我们经常需要在基本数据类型和字符串之间进行转换. 其中,基本类型转换为字符串有三种方法: 1. 使用包装类的 toString() 方法 2. 使 ...

  3. BZOJ 4052: [Cerc2013]Magical GCD

    以一个数字开头的子序列的gcd种类不会超过logn种,因此去找相同gcd最长的位置,更新一下答案,复杂度O(nlogn^2) #include<cstdio> #include<al ...

  4. windows系统调用 进程快照

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

  5. sql 中各种锁随记

    一. 为什么要引入锁    多个用户同时对数据库的并发操作时会带来以下数据不一致的问题:    丢失更新  A,B两个用户读同一数据并进行修改,其中一个用户的修改结果破坏了另一个修改的结果,比如订票系 ...

  6. 批量修改照片名称的shell脚本

    代码这种经常完善的东西,其实是不太适合使用博客来发布的. 以下是一个批量修改照片名称的shell脚本: 事情是这样的,虽然手机拍的照片文件名是按照日期来确定的,但是是这种形式的 IMG_mmddYY_ ...

  7. Asp.net中后台C#数组与前台Javascript数组交互

    摘自:http://blog.csdn.net/a6225301/article/details/20003305 在上一篇<asp.net中javascript与后台c#交互>中实现了前 ...

  8. 天天模拟器 和 Genymotion 设置代理

    之前以为是10.0.3.1或者本机IP,尝试几次都不行,百度之,得到答案,原来genymotion里面网关的IP是10.0.3.2 所以,代理IP要设置为:10.0.3.2

  9. UIViewController启动过程

    流程:判断是否view属性为nil,如果为空,调用loadView方法,如果重写了loadView方法,那么从代码创建普通视图,如果没有重写并且有storyBoard或者xib文件,那么从storyB ...

  10. [置顶] Jquery学习总结(二) jquery选择器详解

    1.基本选择器 l ID 根据元素ID选择 l Elementname 根据元素名称选择 l Classname 根据元素css类名选择 举例: <input type=”text” id=”I ...