hdu-5640 King's Cake (水题)
2016-03-12 22:48
260 查看
题目链接
Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 79 Accepted Submission(s): 69
[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]
2
2 3
2 5
[align=left]Sample Output[/align]
3
4
AC代码:
King's Cake
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 79 Accepted Submission(s): 69
[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]
2
2 3
2 5
[align=left]Sample Output[/align]
3
4
AC代码:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); int ans=0,mmin,mmax; while(n&&m) { if(n>m) { n-=m; } else { m-=n; } ans++; } cout<<ans<<"\n"; } return 0; }
相关文章推荐
- 第33讲项目3——输出这样的整数
- Linux rpm 命令参数使用详解[介绍和应用](转)
- iOS完美版的UIScrollView无缝循环:你值得一看
- vc++中int,char*, float,double,CString之间的类型转换
- LINUX内核分析第三周学习总结:构造一个简单的LINUX系统MENUOS
- eclipse下maven项目保持原有目录结构配置resin运行环境
- centos6 常见目录(纯搬运)
- 2016.3.12 好奇宝宝
- 编程小练习6
- RabbitMQ的几种典型使用场景
- 异常处理
- 面向对象的程序设计(理解对象)
- 面向对象的程序设计(创建对象)
- 九天鸟p2p网贷系统的架构设计
- Example006为弹出窗口加入关闭按钮
- 20145127《java程序设计》第二周学习总结
- [JSOI2008] [BZOJ1013] 球形空间产生器sphere - 高斯消元
- Machine Learning - Neural Networks Representation Part I
- 使用SKIP-GRANT-TABLES 解决 MYSQL ROOT密码丢失(转)
- 第五十天