King's Cake

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 188    Accepted Submission(s): 159

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
hint:
For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$
 
Source
 
题意:n*m的蛋糕 每次只能 切一刀 并且切下来的是正方形 问 最多能切成几个正方形
题解: 模拟过程就可以了
 #include<cstring>
#include<cstdio>
#include<map>
#include<queue>
#include<stack>
#include<set>
using namespace std;
int t;
int n,m;
int main()
{
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d %d",&n,&m);
int t;
int ans=;
int minx=min(n,m);
if(n>m)
{
t=n;
n=m;
m=t;
}
while(n!=m)
{
n=m-minx;
m=minx;
if(n>m)
{
t=n;
n=m;
m=t;
}
minx=min(n,m);
ans++;
}
printf("%d\n",ans+); }
return ;
}

HDU 5640的更多相关文章

  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 5036-Explosion 传递闭包,bitset,期望/概率

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5036 Explosion Time Limit: 6000/3000 MS (Java/Others)   ...

  7. hdu 2825 aC自动机+状压dp

    Wireless Password Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  9. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

随机推荐

  1. es6笔记4^_^function

    一.function默认参数 现在可以在定义函数的时候指定参数的默认值了,而不用像以前那样通过逻辑或操作符来达到目的了. es5 function sayHello(name){ //传统的指定默认参 ...

  2. JS的六大对象:Global、Math、Number、Date、JSON、console,运行在服务器上方的支持情况分析

    在ASP中使用runat="server"来调用JS的相关函数,代码如下: <script runat="server" language="j ...

  3. Java学习笔记-序

    最近开始学习java了,上班看书看得经常瞌睡,有时候想起来觉得挺重要的知识点想记在哪里又害怕忘记了,于是乎突然想到了博客园,所以今天上午就决定记在院子里了,先写了8是因为已经看到第八章了(读的是Jav ...

  4. Python3 数据类型-集合

    在Python中集合set是基本数据类型的一种,它有可变集合(set)和不可变集合(frozenset)两种.创建集合set.集合set添加.集合删除.交集.并集.差集的操作都是非常实用的方法. 集合 ...

  5. wpa_supplicant与kernel交互

    wpa_supplicant与kernel交互的操作,一般需要先明确驱动接口,以及用户态和kernel态的接口函数,以此来进行调用操作.这里分为4个步骤讨论. 1.首先需要明确指定的驱动接口.因为有较 ...

  6. Python函数的内省-Introspection

    Python函数可以进行内省-Introspection,查看函数内部的细节,方式就是使用函数的__code__属性. def func(a, b = 2): return a + b >> ...

  7. LintCode-365.二进制中有多少个1

    二进制中有多少个1 计算在一个 32 位的整数的二进制表式中有多少个 1. 样例 给定 32 (100000),返回 1 给定 5 (101),返回 2 给定 1023 (111111111),返回 ...

  8. [计算机网络-传输层] 面向连接的传输:TCP

    参考:http://blog.csdn.net/macdroid/article/details/49070185 在学习TCP之前我们先来看一下可靠数据传输需要提供什么样的机制: ·差错检测机制:检 ...

  9. DELPHI enablecontrols,disablecontrols函数

    DisableControls方法是在程序修改或后台有刷新记录的时候切断数据组件,如TTABLE.ADOQUERY等等与组件数据源的联系.如果没有切断,数据源中只要一有数据的改动,尤其是批量改动的话, ...

  10. Oracle触发器实现监控某表的CRUD操作

    前提:请用sys用户dba权限登录 1.创建一个表来存储操作日志 create table trig_sql( LT DATE not null primary key, SID NUMBER, SE ...