当前位置: 首页 > news >正文

hdu 5640 King's Cake(模拟)

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
BestCoder Round #75
 

 

模拟,过程类似求gcd,每次减去最小的边即可。

 

 1 #pragma comment(linker, "/STACK:1024000000,1024000000")
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 #include <stack>
15 using namespace std;
16 #define PI acos(-1.0)
17 #define max(a,b) (a) > (b) ? (a) : (b)
18 #define min(a,b) (a) < (b) ? (a) : (b)
19 #define ll long long
20 #define eps 1e-10
21 #define MOD 1000000007
22 #define N 1000000
23 #define inf 1e12
24 int n,m;
25 int main()
26 {
27    int t;
28    scanf("%d",&t);
29    while(t--){
30       scanf("%d%d",&n,&m);
31       int ans=0;
32       while(n!=m){
33          ans++;
34          if(n>m) n-=m;
35          else m-=n;
36       }
37       printf("%d\n",ans+1);
38 
39    }
40     return 0;
41 }
View Code

 

相关文章:

  • 2、Python语法基础
  • Python基础教程第二版 6:抽象
  • UnicodeEncodeError: 'ascii' codec can't encode
  • 【Android 学习】 Android反编译
  • 【转】Java 中的 i = i++
  • 在我lenovo上装windows10
  • Shell编程
  • 构建自己的PHP框架--创建组件的机制
  • 闲扯 『 document.write 』
  • 【vSphere故障案例】案例九:ESXi主机HA未配置错误
  • 在Mac上关于tomcat服务器的安装、配置、启动、部署web详细流程
  • git分享(二)git checkout
  • Android源码大放送之material design类型
  • 国内收益最高的聚合平台--KeyMob移动广告聚合平台
  • SQL 存储过程返回值
  • 《剑指offer》分解让复杂问题更简单
  • Angular数据绑定机制
  • CAP理论的例子讲解
  • DOM的那些事
  • Idea+maven+scala构建包并在spark on yarn 运行
  • IP路由与转发
  • Java超时控制的实现
  • java中的hashCode
  • Js基础知识(一) - 变量
  • Linux快速配置 VIM 实现语法高亮 补全 缩进等功能
  • Mocha测试初探
  • MyEclipse 8.0 GA 搭建 Struts2 + Spring2 + Hibernate3 (测试)
  • php面试题 汇集2
  • React as a UI Runtime(五、列表)
  • React-redux的原理以及使用
  • Spark in action on Kubernetes - Playground搭建与架构浅析
  • Vue ES6 Jade Scss Webpack Gulp
  • vue从创建到完整的饿了么(18)购物车详细信息的展示与删除
  • Vue实战(四)登录/注册页的实现
  • 闭包--闭包作用之保存(一)
  • 二维平面内的碰撞检测【一】
  • 服务器之间,相同帐号,实现免密钥登录
  • 关于for循环的简单归纳
  • 利用jquery编写加法运算验证码
  • 码农张的Bug人生 - 初来乍到
  • 全栈开发——Linux
  • 一起来学SpringBoot | 第三篇:SpringBoot日志配置
  • 最简单的无缝轮播
  • Java总结 - String - 这篇请使劲喷我
  • 阿里云服务器购买完整流程
  • 我们雇佣了一只大猴子...
  • ​【C语言】长篇详解,字符系列篇3-----strstr,strtok,strerror字符串函数的使用【图文详解​】
  • ​决定德拉瓦州地区版图的关键历史事件
  • #pragma data_seg 共享数据区(转)
  • #我与Java虚拟机的故事#连载03:面试过的百度,滴滴,快手都问了这些问题
  • (10)Linux冯诺依曼结构操作系统的再次理解
  • (Java数据结构)ArrayList
  • (MonoGame从入门到放弃-1) MonoGame环境搭建
  • (备忘)Java Map 遍历
  • (附源码)ssm码农论坛 毕业设计 231126