zoukankan      html  css  js  c++  java
  • 2016-2017 ACM-ICPC, NEERC, Northern Subregional Contest F(gym/101142 F)

    gym/101142 F

    题意:给一张长宽W*H的纸, 求最少多少次可以折成长宽 w*h,每次只能平行边缘折

    思路:每次对折是最优的,最后一次不一定对折,但是只计算次数,可以不用管最后一次到底怎么折的,只要第一次折到W<=w H<=h,即可,一共有2种情况:1、W->w , H->h,2、W->h, H->w; 2种情况都要考虑

    AC代码:

    #include "iostream"
    #include "iomanip"
    #include "string.h"
    #include "stack"
    #include "queue"
    #include "string"
    #include "vector"
    #include "set"
    #include "map"
    #include "algorithm"
    #include "stdio.h"
    #include "math.h"
    #pragma comment(linker, "/STACK:102400000,102400000")
    #define bug(x) cout<<x<<" "<<"UUUUU"<<endl;
    #define mem(a,x) memset(a,x,sizeof(a))
    #define step(x) fixed<< setprecision(x)<<
    #define mp(x,y) make_pair(x,y)
    #define pb(x) push_back(x)
    #define ll long long
    #define endl ("
    ")
    #define ft first
    #define sd second
    #define lrt (rt<<1)
    #define rrt (rt<<1|1)
    using namespace std;
    const ll mod=1e9+7;
    const ll INF = 1e18+1LL;
    const int inf = 1e9+1e8;
    const double PI=acos(-1.0);
    const double eps=1e-9;
    const int N=1e5+100;
    
    int main(){
        freopen("folding.in","r",stdin); 
       freopen("folding.out","w",stdout);
        double W,H,w,h;
        int ans1=0,ans2=0;
        cin>>W>>H>>w>>h;
        double W1=W,H1=H;
        if(W<H) swap(W,H);
        if(w<h) swap(w,h);
        if(W<w || H<h){
            cout<<"-1
    ";
            return 0;
        }
        while(W-w>eps){
            W/=2;
            ans1++;
        }
        while(H-h>eps){
            H/=2;
            ans1++;
        }
        if(W1<H1) swap(W1,H1);
        if(w>h) swap(w,h);
        if(W1<w || H1<h) ans2=inf;
        while(W1-w>eps){
            W1/=2;
            ans2++;
        }
        while(H1-h>eps){
            H1/=2;
            ans2++;
        }
        int ans=min(ans1,ans2);
        cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    java监听者模式
    使用tc编写流量控制脚本
    Android apk集成
    就这样
    嘴不笨来试试??太好玩儿了,看看谁厉害?
    老板的三句话
    电脑设置wifi
    JDBC
    使用git的一般操作
    模板引擎Velocity学习系列
  • 原文地址:https://www.cnblogs.com/max88888888/p/7823097.html
Copyright © 2011-2022 走看看