zoukankan      html  css  js  c++  java
  • Codeforces Round #370 (Div. 2) C

    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;
    }
    

      

  • 相关阅读:
    HttpClient POST/GET方法
    Selenium+Java(十一)Selenium窗口切换
    Selenium+Java(十)Selenium常用方法
    Selenium+Java(九)Selenium键盘与鼠标事件
    Selenium+Java(八)Selenium下拉框处理
    Selenium+Java(七)Selenium对话框的处理
    Selenium+Java(六)Selenium 强制等待、显式等待、隐实等待
    [java]对象创建的过程
    [正则表达式] 表达式使用记录
    【Mysql】主从复制
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/5866374.html
Copyright © 2011-2022 走看看