题目链接

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

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
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=,mmin,mmax;
while(n&&m)
{
if(n>m)
{
n-=m;
}
else
{
m-=n;
}
ans++;
}
cout<<ans<<"\n"; }
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

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

  3. 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 ...

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

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

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

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

  6. HDU 5578 Friendship of Frog 水题

    Friendship of Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  7. HDU 5590 ZYB's Biology 水题

    ZYB's Biology Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid ...

  8. HDU 5538 L - House Building 水题

    L - House Building Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.ph ...

  9. Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

随机推荐

  1. Effective C++ 49,50

    49.熟悉标准库. C++标准库非常大. 首先标准库中函数非常多,为了避免名字冲突.使用命名空间std.而之前的库函数都存放于< .h>中,如今成为伪标准库.而不能直接将这些头文件所有直接 ...

  2. Nginx (简体中文)

    博文地址:https://wiki.archlinux.org/index.php/Nginx_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#.E5.AE.89.E8. ...

  3. TP框架---thinkphp中ajax分页

    //点击类别后要显示的内容 public function pagechuli3()//这个方法的功能是根据ajax传过来的值查询数据,再将查询出来的数据返回到ajax,返回的默认是JSON类型. { ...

  4. Linq实现between拓展

    先写一个拓展方法 static class Ext { public static IQueryable<TSource> Between<TSource, TKey> (th ...

  5. EasyDSS视频点播服务器实现多分辨率/多码率无缝切换的办法

    EasyDSS流媒体音视频直播与点播服务器软件,是一套提供一站式的转码.点播.直播.检索.回放.录像下载服务的高性能RTMP/HLS/HTTP-FLV流媒体服务,极大地简化了流媒体相关业务的开发和集成 ...

  6. nginx学习之压缩解压篇(七)

    1.简介 压缩响应可以减少传输数据的大小,节省带宽.但过多的压缩会造成很大的处理开销.在发送给客户端之前,nginx会对响应做压缩,但是如果后端服务器已经 压缩过了,nginx就不再压缩. 2.开启压 ...

  7. appium报'Command 'D\:\\android-sdk-windows\\platform-tools\\adb.exe -P 5037 -s “adb device” shell pm clear appPackage' exited with code 1'

    解决方法:是因为手机开发者模式没有允许USB调试(安全模式),打开即可

  8. python数据分析之:数据聚合与分组运算

    在数据库中,我们可以对数据进行分类,聚合运算.例如groupby操作.在pandas中同样也有类似的功能.通过这些聚合,分组操作,我们可以很容易的对数据进行转换,清洗,运算.比如如下图,首先通过不同的 ...

  9. bd存储

    var sessionData = new Array();var setSessionData=function(key,val){ if(sessionStorage){ sessionStora ...

  10. php匹配字符串中大写字母的位置

    变量名用的是驼峰,数据库中字段中的是下划线,现在想把userId等变量批量转换成user_id,怎么样获取大写字母在字符串中的位置?echo strtolower(preg_replace('/((? ...