HDOJ 5640 king's cake
2016-03-19 11:46
232 查看
[align=left]Problem Description[/align]
It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size
n×m(1≤n,m≤10000)
. The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut the rectangle cake into two pieces, one of which should be a square cake.. Since he loves squares , he will cut the biggest square cake. He will continue
to do that until all the pieces are square. Now can you tell him how many pieces he can get when he finishes.
[align=left]Input[/align]
The first line contains a number
T(T≤1000)
, the number of the testcases.
For each testcase, the first line and the only line contains two positive numbers
n,m(1≤n,m≤10000)
.
[align=left]Output[/align]
For each testcase, print a single number as the answer.
[align=left]Sample Input[/align]
[align=left]Sample Output[/align]
[/code]
It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size
n×m(1≤n,m≤10000)
. The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut the rectangle cake into two pieces, one of which should be a square cake.. Since he loves squares , he will cut the biggest square cake. He will continue
to do that until all the pieces are square. Now can you tell him how many pieces he can get when he finishes.
[align=left]Input[/align]
The first line contains a number
T(T≤1000)
, the number of the testcases.
For each testcase, the first line and the only line contains two positive numbers
n,m(1≤n,m≤10000)
.
[align=left]Output[/align]
For each testcase, print a single number as the answer.
[align=left]Sample Input[/align]
2 2 3 2 5
[align=left]Sample Output[/align]
3 4 hint: For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$[code]#include <cstring> #include <iostream> #include <algorithm> using namespace std; int sum; void cut (int n,int m) { if(n!=m) { if(n>m) { int temp=n; n=m; m=temp; } sum++; cut(n,m-n); } } int main() { int T; cin>>T; for(int k=1;k<=T;k++) { int n,m; sum=0; cin>>n>>m; cut(n,m); cout<<sum+1<<endl; } return 0; }
[/code]
相关文章推荐
- Uva216—— Getting in Line
- knockoutjs十三 focus checked绑定
- C#代码覆盖率实践-vsinstr和OpenCover
- PMD-Java 代码检查工具对 error 和 warning 的配置
- Java IO--创建文件
- TMMi的评估类型
- mysql数据库连接池使用(三)数据库元数据信息反射数据库获取数据库信息
- 读历史书看历史剧
- 深入理解Java虚拟机笔记---垃圾收集器
- mysql数据库连接池使用(三)数据库元数据信息反射数据库获取数据库信息
- HDU 1890 Robotic Sort(splay)
- 电气配件管理系统总结
- 社会热点
- Java初级工程师面试题精选3
- 动态内存和智能指针
- java一周知识回顾
- 并查集详解
- 整理:统计学习-3 k近邻法
- myeclipse 改java文件后禁止自动重启- 热部署
- Java堆栈详解