HDOJ 5640-King's Cake【数学】
2016-03-12 21:49
393 查看
King's Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 0 Accepted Submission(s): 0
[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 hint: For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$
[align=left]Source[/align]
BestCoder Round #75
解题思路:
一块蛋糕每次切下一个正方形,问能切几个正方形。
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; int main() { int T; scanf("%d",&T); while(T--) { int n,m; int ans=0; scanf("%d%d",&n,&m); for(;;) { int yy=max(n,m)/min(n,m); int xx=max(n,m)-min(n,m)*yy; ans+=yy; if(xx==0) break; if(max(n,m)!=min(n,m)) { if(max(n,m)==n) { n=n-m*yy; continue; } if(max(n,m)==m) { m=m-n*yy; continue; } } else { m=m-n*yy; } } printf("%d\n",ans); } return 0; }
相关文章推荐
- 类加载器以及双亲委派模型介绍
- mac下使用Navicat
- android gradle plugin 1.3.0 以上使用 public.xml 固定 id
- Java配置环境变量
- MySql数据库乱码
- PyQt5 - QWidgets部件进阶教程之字符映射表
- Java Thread Join Example with Explanation
- 【leetcode】Array——Jump Game2(45)
- 【转】powerdesigner 数据类型与数据库数据类型对应
- 一个深度学习博客
- git基本操作
- C++ 学习之路(5):友元函数与友元类
- 斗地主游戏-应用程序-01
- 回归博客 学会思考
- 区间求交集算法
- MFC对话框-DoDataExchange()函数使用
- 使用session技术来实现网上商城购物车的功能
- 输出星号图
- AdaBoost算法1(基于单层决策树)
- day60:sparkSql