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 ...
随机推荐
- python设计模式之迭代器与生成器详解(五)
前言 迭代器是设计模式中的一种行为模式,它提供一种方法顺序访问一个聚合对象中各个元素, 而又不需暴露该对象的内部表示.python提倡使用生成器,生成器也是迭代器的一种. 系列文章 python设计模 ...
- Opencv 配置VS2012
开始接触图像处理有一段时间了,经过前期的调研,和相关入门知识的学习,开始接触一些图像处理应用的工具.Opencv是一个图像处理的开源库,由于其开放的协议架构,国内外很多科研机构和团队都在基于openc ...
- 日常开发技巧:x11-forward,使用远程机器的gui程序
背景 日常用过ssh登录服务器进行工作,尽管大部分时间,都只需要终端操作,编辑源码也是vim就够用了. 但有时候,还是需要使用gui程序的,比如打开一份pdf,word,ppt,excel等. 碰到这 ...
- 无状态Http
无状态的根本原因 浏览器和服务器使用socket通信,服务器将请求结果返回给浏览器后,会关闭当前socket连接.而且服务器会在处理页面完毕后销毁页面对象. 应用层面的原因 浏览器和服务器之间通信都遵 ...
- windows下制作debian U盘启动
制作平台:Windows 7 制作debian版本:debian 7.4 wheezy 1.下载引导镜像,包含三个文件:boot.img.gz(解压备用).initrd.gz 和 vmlinuz. h ...
- HDU 2594 Simpsons’ Hidden Talents(KMP求s1前缀和s2后缀相同部分)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2594 题目大意:给两串字符串s1,s2,,找到最长子串满足既是s1的前缀又是s2的后缀,输出子串,及相 ...
- Fiddler Web Session 列表(1)
Web Session 列表 位置: Web Session 列表 位于Fiddler界面的左侧 ,是Fiddler所抓取到的所有Session会话的列表集合. Web Session 列表 栏名词解 ...
- java1.8环境配置+win10系统
Java环境配置相关 Java jdk 1.8版本的环境配置和1.7版本 存在一些差异,当然不同的操作系统可能会对jdk配置有一定的变化.本文我主要说1.8版本的jdk在window10 系统上的配置 ...
- 05 java 基础:运算符、程序结构
赋值运算符 : = 三元运算符 : ? 算术运算符 : +.- .*./.% 自增自减运算符: ++.-- 关系运算符:>.<.==.>=.<=.!= 逻辑运算符 :& ...
- js求区间随机数
function rnd(n, m){ var random = Math.round(Math.random()*(m-n)+n); return random; }