计蒜客 folding
来源:互联网 发布:c语言心形图案代码下载 编辑:程序博客网 时间:2024/06/09 23:11
folding
As you can remember, Alex is fond of origami. She switched from squares to rectangles, and rectangles are much more difficult to master. Her main interest is to determine what is the minimum possible number of folds required to transform W × H rectangle tow × h one. The result of each fold should also be 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.
Input
The first line of the input contains two integersW and H — the initial rectangle dimensions. The second line contains two more integersw and h — the target rectangle dimensions (1≤ W, H, w, h≤ 10910^9109).
Output
Output a single integer — the minimum required number of folds to transform the initial rectangle to the target one.
If the required transformation is not possible, output−1.
样例输入1
2 72 2
样例输出1
2
样例输入2
10 64 8
样例输出2
2
样例输入3
5 51 6
样例输出3
-1
In 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 be parallel to the rectangle sides).
#include<iostream>#include<cstdio>#include<cstring>#include<string>using namespace std;#define INF 0x3f3f3f3fint main(){ int n,m; int a,b; scanf("%d%d",&n,&m); scanf("%d%d",&a,&b); if(n>m)swap(n,m); if(a>b)swap(a,b); int g=0,h=0; if(a>n || b>m)printf("-1\n"); else { int ans=INF; for(int i=0;i<2;i++) { if(i==1) swap(n,m); g=0,h=0; int maxn=n/2; int nn=n; while(nn-maxn>=a && n!=a && maxn!=0) { g++; nn-=maxn; maxn=nn/2; } if(nn>a)g++; maxn=m/2; int mm=m; while(mm-maxn>=b && m!=b && maxn!=0) { h++; mm-=maxn; maxn=mm/2; } if(mm>b)h++; ans=min(ans,g+h); } printf("%d\n",ans); } return 0;}
- 计蒜客 folding
- Folding
- 计蒜客————Folding
- Folding@home
- poj2176 Folding
- Paper folding
- UVA1630 - Folding
- Area Folding
- Folding Gym
- Word Folding
- Folding UVA
- UVa1630 Folding/poj 2176 Folding/zoj 1554 Folding
- ZOJ 1554 Folding
- HDU--4134(Sequence Folding)
- zoj 1554 Folding
- POJ 2176 Folding (字符串)
- HDU4134:Sequence Folding
- 常量折叠 Constant folding
- 2018 安卓
- 善恶报应
- kvm虚拟化基础:运行级别
- 剑指Offer------最小的k个数
- android传输层tcp套接字通信
- 计蒜客 folding
- 【089】深度学习读书笔记:P29证明迹Tr(AB)=Tr(BA)
- android学习---使用Handler
- MySQL主从复制
- 离线赛20171004总结
- R学习:用REmap生成我们自己的迁徙地图
- 漫话中文自动分词和语义识别
- Java中有int[26] for Letters ‘a’
- OAF框架的基本思想--基于MVC模式