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. Mac配置环境变量(Java,Android,Gradle,Maven,Hosts)

    JAVA_HOME 配置环境变量 # 使用vim打开.bash_profile文件,加入java环境变量 $ vim .bash_profile export JAVA_HOME=$(/usr/lib ...

  2. 夺命雷公狗---DEDECMS----33dedecms自定义搜索以及分页功能完成

    我们现在要开始实现模版里面的搜索功能了,我们先找要做出一个检索提交表单,如下所示: 只要我们点击生成之后我们的表单就获取到了,可以直接拿生成好的html表单拿来用来测试下.. 将他嵌入首页的模版文件, ...

  3. (function($){...})(jQuery) 函数详解

    function(arg){...} 这是一个匿名函数,参数是arg. 而调用匿名函数时,是在函数后面写上括号和实参的,由于操作符的优先级,函数本身也需要用括号,即: function(arg){.. ...

  4. V4L2驱动程序框架架构【转】

    本文转载自:http://blog.csdn.net/tommy_wxie/article/details/11728809 1 V4L2简介 video4linux2(V4L2)是Linux内核中关 ...

  5. python any()和all()用法

    #any(x)判断x对象是否为空对象,如果都为空.0.false,则返回false,如果不都为空.0.false,则返回true #all(x)如果all(x)参数x对象的所有元素不为0.''.Fal ...

  6. (转载)CSV 文件处理 PERL

    http://cn.perlmaven.com/how-to-read-a-csv-file-using-perl http://search.cpan.org/~hmbrand/Text-CSV_X ...

  7. [转]AngularJS的$resource

    转自:http://blog.csdn.net/violet_day/article/details/17403207 $http $http服务是基于$q服务的,提供了promise封装,它接受一个 ...

  8. 给NIOS II CPU添加一颗澎湃的心——sysclk的使用

    给NIOS II CPU添加一颗澎湃的心——系统时钟的使用 本实验介绍如何在Qsys中添加一个定时器作为NIOS II的心跳定时器,并在NIOS II中软件编程使用该定时器. 将上一个实验watchd ...

  9. 做一个MVC4的项目时留下的经验--增加IPrange

    /* CR#1796870 modify by v-yangwu, add a js file to control the page controls. */ $(document).ready(f ...

  10. vsftpd

    vi /etc/vsftpd.conf and add the following allow_writeable_chroot=YES sudo service vsftpd restart