博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5640 King's Cake(模拟)
阅读量:5923 次
发布时间:2019-06-19

本文共 1728 字,大约阅读时间需要 5 分钟。

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
22 32 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
 

 

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

 

1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 #include
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 long20 #define eps 1e-1021 #define MOD 100000000722 #define N 100000023 #define inf 1e1224 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

 

转载地址:http://ngxvx.baihongyu.com/

你可能感兴趣的文章
统一沟通-技巧-4-让国内域名提供商“提供”SRV记录
查看>>
cocos2d-x 3.0事件机制及用户输入
查看>>
比亚迪速锐F3专用夏季座套 夏天坐垫 四季坐套
查看>>
C++ 数字转换为string类型
查看>>
程序员全国不同地区,微信(面试 招聘)群。
查看>>
【干货】界面控件DevExtreme视频教程大汇总!
查看>>
闭包 !if(){}.call()
查看>>
python MySQLdb安装和使用
查看>>
Java小细节
查看>>
poj - 1860 Currency Exchange
查看>>
chgrp命令
查看>>
Java集合框架GS Collections具体解释
查看>>
洛谷 P2486 BZOJ 2243 [SDOI2011]染色
查看>>
linux 笔记本的温度提示
查看>>
(转)DOTA新版地图6.78发布:大幅改动 增两位新英雄
查看>>
数值积分中的辛普森方法及其误差估计
查看>>
Web service (一) 原理和项目开发实战
查看>>
跑带宽度多少合适_跑步机选购跑带要多宽,你的身体早就告诉你了
查看>>
广平县北方计算机第一届PS设计大赛
查看>>
深入理解Java的接口和抽象类
查看>>