Gym - 101142F Folding(折半)
来源:互联网 发布:jdk 7u80 windows x32 编辑:程序博客网 时间:2024/05/21 06:49
传送门
As you can remember, Alex is fond of origami. She switched from squares to rectangles, and rectanglesare much more difficult to master. Her main interest is to determine what is the minimum possiblenumber of folds required to transform W × H rectangle to w × h one. The result of each fold should alsobe rectangular, so it is only allowed to make folds that are parallel to the sides of the rectangle.Help Alex and write a program that determines the minimum required number of folds.InputThe first line of the input contains two integers W and H — the initial rectangle dimensions. The secondline contains two more integers w and h — the target rectangle dimensions (1 ≤ W, H, w, h ≤ 10^9).OutputOutput a single integer — the minimum required number of folds to transform the initial rectangle tothe target one.If the required transformation is not possible, output −1.Examplesfolding.in 2 72 210 64 85 51 6folding.out22-1In the first example you should fold 2 × 7 rectangle to 2 × 4, and then to 2 × 2.In the second example you should fold 10 × 6 rectangle to 10 × 4, then to 8 × 4, and rotate it to 4 × 8.In the third example it is impossible to fold 5 × 5 rectangle to 1 × 6 one (remember that folds must beparallel to the rectangle sides).
题目大意:
给了一个
样例解释:
Input:
2 7
2 2
Output:
2
首先将
解题思路:
首先我们很容易想到是
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;typedef long long LL;const LL INF = 1e18+5;LL Solve(LL mx, LL mn){ if(mn > mx) return INF; LL cnt = 0; while(mx > mn){ mx = (mx+1)>>1LL; cnt++; } return cnt;}int main(){ ///freopen("folding.in","r",stdin); ///freopen("folding.out","w",stdout); LL w, h ,ww, hh; while(cin>>w>>h>>ww>>hh){ LL TW = max(w,h); LL TH = min(w,h); LL tw = max(ww,hh); LL th = min(ww,hh); if(tw > TW){ puts("-1"); continue; } if(th > TH){ puts("-1"); continue; } ///cout<<max(Solve(TW, tw)+Solve(TH,th),Solve(TW,th)+Solve(TH,tw))<<endl; cout<<min(Solve(TW, tw)+Solve(TH,th),Solve(TW,th)+Solve(TH,tw))<<endl; } return 0;}
0 0
- Gym - 101142F Folding(折半)
- Gym 101142F Folding
- Codeforces Gym 101142 F. Folding
- Folding Gym
- codeforces gym 101142 F(思维)
- [Gym-101350F] F
- Gym 100685F Flood(拓扑排序)
- Gym - 100512F Funny Game(杂题)
- GYM 100247 F. Battle Fury(二分)
- GYM 100090 F.Asperger Syndrome(set)
- GYM 100488 F.Two Envelopes(水~)
- GYM 101102 F.Exchange(水~)
- GYM 101173 F.Free Figurines(贪心)
- GYM 100971 F.Two Points(三分)
- GYM 101086 F.Hey JUDgE(枚举)
- GYM 101061 F.Fairness(dp)
- Gym 101201F Illumination(2-sat)
- Gym 100685 F Flood
- Hdu 4008 Parent and son(给你一棵树(n<=1e5),有Q次查询,每次输入X Y,意思是以X为根,输出Y的儿子节点中节点标号最小和子树中标号最小)
- 洛谷3376 网络最大流
- JQuery插件之-----Datatables(四)render与日期转换(moment.js)
- 51nod 1315 合法整数集
- C语言链式结构表2
- Gym - 101142F Folding(折半)
- 51nod 1316 回文矩阵
- php处理我的关注和关注我的
- 51nod 1319 跳跃游戏
- Android NDK for Eclipse
- Java经典算法(四)
- 返回栈
- Cordova中设置设备锁定横屏竖屏
- 51nod 1320 合法尾数序列