zoukankan      html  css  js  c++  java
  • 嵊州普及Day5T2

    题意:将(w,h)的纸条折成(W,H),最少需几步。

    思路:横竖互不干扰,然后最多可折int型一半,拿个函数判断两次比较即可,然后折不了的条件是需要的矩形大于给的矩形。

    见代码:

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    int w,h,W,H,ans=0,sum;
    void fold(int h,int l,int x,int y)
    {
        if(h>=x&&l>=y)
        {   
            if(h!=x)
            while(h-x>=h/2)
            {
                h-=h/2;ans++;
                if(h==x)
                break;
            }
            if(h!=x)
            ans++;
            if(l!=y)
            while(l-y>=l/2)
            {
                l-=l/2;ans++;
                if(l==y)
                break;
            }
            if(l!=y)
            {
             ans++;
            }
        }
    }
    int main()
    {
        freopen("folding.in","r",stdin);
        freopen("folding.out","w",stdout);
        cin>>w>>h>>W>>H;
        int a=w,b=h;
        fold(w,h,W,H);
        w=a;
        h=b;
        sum=ans;
        ans=0;
        fold(w,h,H,W);
        if(sum!=0&&ans!=0)
        ans=min(sum,ans);
        else
        {
            if(ans==0)
            ans=sum;
        }
        if((w==W&&h==H)||(w==H&&h==W))
        {
            cout<<0<<endl;
            return 0;
        }
        if(ans==0)
        cout<<-1;
        else
        cout<<ans<<endl;
        return 0;
    }

    好题哉!!!

  • 相关阅读:
    Asp.net的安全问题
    周末了
    GDI+ 取得文本的宽度和高度
    Family的解释
    日语:名词并列
    第一次来入住园里
    All About Floats
    smarty的基本配置
    apache:一个ip绑定多个域名的问题
    CSS Overflow属性详解
  • 原文地址:https://www.cnblogs.com/qing1/p/11191373.html
Copyright © 2011-2022 走看看