HDU 5640 King's Cake GCD
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的更多相关文章
- HDU 5640 King's Cake
King's Cake Problem Description It is the king's birthday before the military parade . The ministers ...
- 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 ...
- hdu 5640 King's Cake(模拟)
Problem Description It is the king's birthday before the military parade . The ministers prepared ...
- HDU 5640 King's Cake【模拟】
题意: 给定长方形,每次从中切去一个最大的正方形,问最终可以得到多少正方形. 分析: 过程类似求gcd,每次减去最小的边即可. 代码: #include <cstdio> #include ...
- hdu 4454 Stealing a Cake(三分之二)
pid=4454" target="_blank" style="">题目链接:hdu 4454 Stealing a Cake 题目大意:给定 ...
- HDU 5640
King's Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total ...
- hdu-5640 King's Cake (水题)
题目链接 King's Cake Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- hdu 5381 The sum of gcd(线段树+gcd)
题目链接:hdu 5381 The sum of gcd 将查询离线处理,依照r排序,然后从左向右处理每一个A[i],碰到查询时处理.用线段树维护.每一个节点表示从[l,i]中以l为起始的区间gcd总 ...
- HDU 5642 King's Order 动态规划
King's Order 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5642 Description After the king's speec ...
随机推荐
- SurfaceFlinger 讲解
SurfaceFlinger是Android multimedia的一个部分,在Android 的实现中它是一个service,提供系统 范围内的surface composer功能,它能够将各种应用 ...
- Spring Boot学习——单元测试
本随笔记录使用Spring Boot进行单元测试,主要是Service和API(Controller)进行单元测试. 一.Service单元测试 选择要测试的service类的方法,使用idea自动创 ...
- GPS位置模拟-安卓
测试定位功能时都需要位置模拟,一般有如下3种方式: a)手机上安装第三方模拟软件:需要Root: b)PC模拟其中运行app并模拟位置:不能在真机上运行,手机兼容性不能测试到: b)在app中让开发增 ...
- 洛谷P1008三连击 题解
题目传送门 使用dfs搜索,搜索9个数字,注意回溯...最后判断是否符合条件,输出. #include<bits/stdc++.h> using namespace std; ],a[]; ...
- 语音性别识别 - 使用R提取特征
步骤 1)安装R.windows操作系统安装包的链接:https://cran.r-project.org/bin/windows/base/ 2)切换当前路径为脚本所在路径 点击 文件 > 改 ...
- thinkphp5.1使用phpstudy隐藏index.php
apache的重写规则如下: <IfModule mod_rewrite.c> Options +FollowSymlinks -Multiviews RewriteEngine on R ...
- jquery放大镜非常漂亮噢
这个放大镜的代码挺简单滴效果也不错. <script> //QQ:496928838 微凉 $(function(){ $("#demo").enlarge( { // ...
- 洛谷P3052 [USACO12MAR]摩天大楼里的奶牛 [迭代加深搜索]
题目传送门 摩天大楼里的奶牛 题目描述 A little known fact about Bessie and friends is that they love stair climbing ra ...
- CPPUNIT_TEST
(1) CPPUNIT_ASSERT(condition):判断condition的值是否为真,如果为假则生成错误信息. (2)CPPUNIT_ASSERT_MESSAGE(message, cond ...
- Python-函数总结
把程序分解成较小的部分,主要有3种方法. 函数(function) 对象(object) 模块(module) 本节我们先学习函数.函数是带名字的代码块,可以把多个逻辑封装起来.这样就可以在程序中可以 ...