King's Cake

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5640

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

hint:

For the first testcase you can divide the into one cake of \(2\times2\) , 2 cakes of \(1\times 1\)

Hint

题意

给一个n*m的矩形

你每次可以消去这个矩形中最大的正方形。

问你最多可以消去多少次。

题解:

像求GCD那样切就好了。

当然辗转相减法也是兹瓷的。

代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<math.h>
using namespace std; int main()
{
int t;scanf("%d",&t);
while(t--)
{
int n,m;
scanf("%d%d",&n,&m);
int ans = 0;
while(n&&m)
{
if(n>m)swap(n,m);
m-=n;
ans++;
}
cout<<ans<<endl;
}
}

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

  1. HDU 5640 King's Cake

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

  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 5381 The sum of gcd(线段树+gcd)

    题目链接:hdu 5381 The sum of gcd 将查询离线处理,依照r排序,然后从左向右处理每一个A[i],碰到查询时处理.用线段树维护.每一个节点表示从[l,i]中以l为起始的区间gcd总 ...

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

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

随机推荐

  1. win10环境变量

    jdk8 JAVA_HOME D:\devsoft\jdk\jdk1.8 CLASSPATH .;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar pa ...

  2. Getting Started with Django Rest Framework and AngularJS

    转载自:http://blog.kevinastone.com/getting-started-with-django-rest-framework-and-angularjs.html A ReST ...

  3. [ python ] 格式化输出、字符集、and/or/not 逻辑判断

    格式化输出 %: 占位符 s: 字符串 d: 数字 %%: 表示一个%, 第一个%是用来转义 实例: name = input('姓名:') age = int(input('年龄:')) print ...

  4. acm专题---键树

    题目来源:http://hihocoder.com/problemset/problem/1014?sid=982973 #1014 : Trie树 时间限制:10000ms 单点时限:1000ms ...

  5. PTP简介

    PTP简介 在通信网络中,许多业务的正常运行都要求网络时钟同步,即整个网络各设备之间的时间或频率差保持在合理的误差水平内.网络时钟同步包括以下两个概念: l              时间同步:也叫相 ...

  6. POJ 3279 Fliptile(DFS+反转)

    题目链接:http://poj.org/problem?id=3279 题目大意:有一个n*m的格子,每个格子都有黑白两面(0表示白色,1表示黑色).我们需要把所有的格子都反转成黑色,每反转一个格子, ...

  7. 从输入URL到显示页面的过程分析

    作为一个软件开发者,你一定会对网络应用如何工作有一个完整的层次化的认知,同样这里也包括这些应用所用到的技术:像浏览器,HTTP,HTML,网络服务器,需求处理等等. 本文将更深入的研究当你输入一个网址 ...

  8. C#矩形框沿直线移动

    C#中用GDT+的一系列方式,可以绘制各种图形:点,直线,圆形,矩形...... C#中这些图形的绘制,一般教程的demo中给出的代码,是在Form1_Paint(object sender, Pai ...

  9. 报错org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet"

    org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n ...

  10. 关于<c:if>没有<c:else>解决方案-转载

    <c:if>没有<c:else>可以用<c:choose>来取代结构: <c:choose> <c:when test=""& ...