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. eclipse批量删除断点(转)

    1.首先调出BreakPoints选项卡(Window--show View--Other--BreakPoints). 2.选择BreakPoints选项卡,选择所有断点,点击删除即可. 

  2. checkbox的相关知识点

    1.获取单个checkbox选中项(三种写法)$("input:checkbox:checked").val()或者$("input:[type='checkbox']: ...

  3. JSon_零基础_005_将po(bean)对象转换为JSon格式的对象字符串,返回给界面

    将po(bean)对象转换为JSon格式的对象字符串,返回给界面 导入jar包: 编写po(bean)类: package com.west.webcourse.po; /** * 第01步:编写be ...

  4. redis连接数问题

    redis连接数查看 info client redis连接数满了,不会继续建立连接. 造成redis连接数满了原因有很多. 1.建立新连接不close()的话redis连接不会回归连接池. 显示所有 ...

  5. LDA-math-MCMC 和 Gibbs Sampling

    http://cos.name/2013/01/lda-math-mcmc-and-gibbs-sampling/ 3.1 随机模拟 随机模拟(或者统计模拟)方法有一个很酷的别名是蒙特卡罗方法(Mon ...

  6. [MacOS] xcrun: error: active developer path ("/Volumes/Xcode/Xcode6-Beta.app/Contents/Developer") does not exist, use xcode-select to change

    When using MacOS with xcode6-beta, i always meet these error: xcrun: error: active developer path (& ...

  7. linux中查看硬件温度的命令

    用到的命令是: sensors 这个命令来自一个叫 lm_sensors 的包. 执行 sensors-detect 可以以询问的方式做一些配置(可以选择检测哪些硬件的温度).

  8. PIC18F中断定时器

    //基于MCC18编译器,使用HI-PICC不可用 //-------------------------------------------- #include <p18F452.h> ...

  9. web跨页弹窗选值

    最近在项目中看到这样一种效果——点击当前网页文本框,然后弹出一个缩小的网页,并在网页里选择或填写数据,然后又返回当前网页,小网页关闭.感觉非常不错,其实在以前网上也看见过,只是当时没有留心.今天抽时间 ...

  10. UIView完全置顶的方法

    一般来说,若需要独立添加一个UIView,使其覆盖于整个应用窗口之上,是这样实现的: AppDelegate *app = (AppDelegate *)[[UIApplication sharedA ...