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;
    }
  • 相关阅读:
    MS Office CVE-2015-1641 恶意 Exploit 样本分析
    Qbot回归,已感染5.4万台计算机
    工具推荐:Backdoor-apk,安卓APK文件后门测试工具
    安卓微信、QQ自带浏览器 UXSS 漏洞
    延迟注入工具(python)
    小白欢乐多——记ssctf的几道题目
    使用转义防御XSS
    富文本存储型XSS的模糊测试之道
    k8s故障总结
    CentOS7.6部署k8s环境
  • 原文地址:https://www.cnblogs.com/max88888888/p/7823097.html
Copyright © 2011-2022 走看看