zoukankan      html  css  js  c++  java
  • 折纸

    折纸

    【问题描述】
    在非常紧张的 NOIP 考试中,有人喜欢啃指甲,有人喜欢转铅笔,有人喜欢撕
    纸条,……而小 x 喜欢迷折纸。
    现有一个 W * H 的矩形纸张,监考老师想知道,小 x 至少要折多少次才能使
    矩形纸张变成 w * h 的矩形纸张。
    注意,每次的折痕都要平行于纸张的某一条边。
    【输入格式】
    第一行包括两个整数 W,H。
    第二行包括两个整数 w,h。
    【输出格式】
    输出一个整数,表示至少需要折的次数。若无解,则输出-1。
    【输入输出样例】
    Input1 2 7 2 2
    Output1 2
    Input2 5 5 1 6
    Output2 -1
    Input3 10 6 4 8
    Output3 2
    【数据说明】
    对于 20% 的数据满足:W = w 且 H,h≤3。
    对于 100% 的数据满足: 1 ≤ W,H,w,h ≤ 9 10 。

    Code

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    int main()
    {    
        long long w,h,x,y,ans=0;
        cin>>x>>y;
        cin>>w>>h;
        if((x<w&&y<w)||(x<h&&y<h))
        {
            cout<<"-1";
            return 0;
        }    
        else
        if((x==w&&y==h)||(x==h&&y==w))
        {
            cout<<"0";
            return 0;
        } 
        else
        {
            swap(x,y);
            swap(w,h);
            while(x>w)
          {
            if(w>(x/2))
            {
                ans++;
                break;
            }
            else
            {
                x=x/2;
                ans++;
            }
           }
            while(y>h)
           {
            if(h>(y/2))
            {
                ans++;
                break;
            }
            else
            {
                y=y/2;
                ans++;
            }
           }
        cout<<ans;    
        }
        return 0;
    }

    思路:

    没啥好说的,自己拿张纸折一折就知道了。

    完结撒花!!!

  • 相关阅读:
    PHP对象的遍历
    PHP对象的复制
    PHP面向对象之类的自动加载
    PHP面向对象之接口
    PHP面向对象之重载
    PHP面向对象之抽象类,抽象方法
    PHP面向对象之final关键字
    PHP面向对象之重写
    使用python操作word
    vc++使用cookie登录网站
  • 原文地址:https://www.cnblogs.com/YYCether666/p/11191301.html
Copyright © 2011-2022 走看看