计蒜客————Folding
来源:互联网 发布:大麦盒子软件下载 编辑:程序博客网 时间:2024/06/03 23:39
- 30.64%
- 2000ms
- 262144K
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 to w × 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 integers Wand H — the initial rectangle dimensions. The second line contains two more integers w and h — the target rectangle dimensions (1 ≤ W, H, w, h ≤ 109).
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
上面所给矩形折叠成下边所给矩形的最小折叠次数..模拟一下就好.
#include<iostream>#include<cstdio>#include<algorithm>using namespace std;int func2(int x1,int x2){ if(x2==x1) return 0; for(int i=1;;i++){ x2*=2; if(x2>=x1) return i; }}int func1(int x1,int y1,int x2,int y2) { if(x1<x2||y1<y2) return -1; return func2(x1,x2)+func2(y1,y2);}int main() { int x1,x2,y1,y2; while(~scanf("%d%d%d%d",&x1,&y1,&x2,&y2)){ int t1=func1(x1,y1,x2,y2),t2=func1(x1,y1,y2,x2); if(t1==-1||t2==-1) printf("%d\n",max(t1,t2)); else printf("%d\n",min(t1,t2)); } return 0;}
- 计蒜客————Folding
- uva 1630——Folding
- LINTCODE——Folding Array
- 修复mercurial 错误 —— abort: case-folding collision between XXX
- UVA 1630 Folding——区间DP(记忆化搜索)
- 计蒜客 folding
- Folding
- 100道动态规划——7 UVA 1630 folding 因为自己考虑的不周全WA了好几发。。。递推,KMP求子串周期
- 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
- P1046 陶陶摘苹果
- 位操作的tips
- AWS系列:深入了解IAM和访问控制
- 分支限界法:布线问题
- 念数字
- 计蒜客————Folding
- Makefile 构建工程,如果加载opencv等第三方库
- Linux学习(二十三):IO模型
- ORM
- #########WOE 评分模型 在logistics regression算法在评分卡上的实践
- MySQL数据库安装与配置详解
- Ubuntu下给普通或新增用户赋予sudo权限
- zabbix监控一---zabbix服务端部署
- First Missing Positive--LeetCode