King's Cake

Problem Description
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.
 
Input
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).
 
Output
For each testcase, print a single number as the
answer.
 
Sample Input
2
2 3
2 5
 
Sample Output
3
4
 
Recommend
wange2014
题目大意:阅兵式前一天,是国王的生日,大臣们为他准备了一个 n *m(1<=n, m<=10000)的蛋糕。他准备切蛋糕,但他切蛋糕有奇奇怪怪的癖好,他每次只切一刀,切下一个正方形蛋糕。请问它最多能切出多少个正方形蛋糕?
思路:看图
 
#include <iostream>
#include <cstdio>
using namespace std;
int t;
int f(int m, int n)
{
if(m<n) return (f(n,m));
t += m/n;
if(m%n==) return ;
f(n,m%n);
}
int main()
{
int m, n, T;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &m, &n);
t=;
f(m, n);
printf("%d\n", t);
}
return ;
}

HDU 5640 King's Cake的更多相关文章

  1. HDU 5640 King's Cake GCD

    King's Cake 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5640 Description It is the king's birthd ...

  2. hdu 5640 King's Cake(BestCoder Round #75)

    King's Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  3. hdu 5640 King's Cake(模拟)

    Problem Description   It is the king's birthday before the military parade . The ministers prepared ...

  4. HDU 5640 King's Cake【模拟】

    题意: 给定长方形,每次从中切去一个最大的正方形,问最终可以得到多少正方形. 分析: 过程类似求gcd,每次减去最小的边即可. 代码: #include <cstdio> #include ...

  5. hdu 4454 Stealing a Cake(三分之二)

    pid=4454" target="_blank" style="">题目链接:hdu 4454 Stealing a Cake 题目大意:给定 ...

  6. HDU 5640

    King's Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total ...

  7. hdu-5640 King's Cake (水题)

    题目链接 King's Cake Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others ...

  8. HDU 5642 King's Order 动态规划

    King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...

  9. BestCoder Round #75 1001 - King's Cake

    Problem Description It is the king's birthday before the military parade . The ministers prepared a ...

随机推荐

  1. SQL Server数据库性能优化(一)之 优化SQL 语句

    最近工作上基本没什么需求(好吧 不是最近是好久了,所以随便看看基础的东西来填补自己的空白) 原文出自:http://www.blogjava.net/allen-zhe/archive/2010/07 ...

  2. LDA-math-MCMC 和 Gibbs Sampling

    http://cos.name/2013/01/lda-math-mcmc-and-gibbs-sampling/ 3.1 随机模拟 随机模拟(或者统计模拟)方法有一个很酷的别名是蒙特卡罗方法(Mon ...

  3. Html基础知识讲解

    Html基础知识讲解 <title>淄博汉企</title> </head> <body bgcolor="#66FFCC" topmar ...

  4. JSP-07-使用JavaBean封装数据

    7.1 常命包名 Dao 包中的接口(NewsDao)以及类(NewsDaoImpl)注意负责和数据操作相关的事情. Service 包中的接口和类对dao的方法进行封装和调用,注意负责和业务逻辑相关 ...

  5. linux中使用软链接时出现 too many levels of symbolic links

    刚开始使用的源文件的路径是相对路径,所以导致标题中的这种错误. 只要用绝对路径表示源文件就好了.如果用相对路径的话,实际相对的是目标文件所在的路径,而在创建链接文件时用的路径是相对于当前的路径.

  6. C语言初学者代码中的常见错误与瑕疵(14)

    见:C语言初学者代码中的常见错误与瑕疵(14) 相关链接:http://www.anycodex.com/blog/?p=87

  7. c#中 ==与equals有什么区别【转】

    转至http://www.zybang.com/question/2263895f201ffec6c68b6c304ac4cd61.html 对于值类型.引用类型来说比较过程怎样的?using Sys ...

  8. android 学习随笔十五(Activity的生命周期与摧毁时返回数据 )

    1.Activity的生命周期 onCreate:创建时调用 onStart:在屏幕上可见,但是还没有获得焦点 onResume:可见并且获得焦点 onPause:可见,但是失去焦点 onStop:不 ...

  9. python随机数的使用记录

    一.random模块简介 Python标准库中的random函数,可以生成随机浮点数.整数.字符串,甚至帮助你随机选择列表序列中的一个元素,打乱一组数据等. 二.random模块重要函数 1 ).ra ...

  10. JavaEE基础(十九)/异常和File

    1.异常(异常的概述和分类) A:异常的概述 异常就是Java程序在运行过程中出现的错误. B:异常的分类 通过API查看Throwable Error 服务器宕机,数据库崩溃等 Exception ...