有趣问题:长方形不断分割掉最大正方形(5640)
来源:互联网 发布:管理电脑桌面的软件 编辑:程序博客网 时间:2024/04/28 23:09
King's Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 444 Accepted Submission(s): 363
Problem Description
It is the king's birthday before the military parade . The ministers prepared a rectangle cake of sizen×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 numbersn,m(1≤n,m≤10000) .
For each testcase, the first line and the only line contains two positive numbers
Output
For each testcase, print a single number as the answer.
Sample Input
22 32 5
Sample Output
34
求解过程很像求两数的最大公约数。
/*------------------Header Files------------------*/#include <iostream>#include <cstring>#include <string>#include <cstdio>#include <algorithm>#include <cstdlib>#include <ctype.h>#include <cmath>#include <stack>#include <queue>#include <deque>#include <map>#include <vector>#include <limits.h>using namespace std;/*------------------Definitions-------------------*/#define LL long long#define PI acos(-1.0)#define INF 0x3F3F3F3F#define MOD 10E9+7#define MAX 500050/*---------------------Work-----------------------*/void work(){int T; cin>>T;while(T--){int n,m;scanf("%d%d",&n,&m);int a,b,cnt=0;while(1){a=max(m,n),b=min(m,n);cnt+=a/b;if(a%b==0) break;m=a-a/b*b,n=b;}printf("%d\n",cnt);}}/*------------------Main Function------------------*/int main(){//freopen("test.txt","r",stdin);//freopen("cowtour.out","w",stdout);//freopen("cowtour.in","r",stdin);work();return 0;}
0 0
- 有趣问题:长方形不断分割掉最大正方形(5640)
- 问题 F: 正方形、长方形、立方体
- UVA10480 打印最大流割掉了哪条边..
- 最大长方形
- 最大长方形
- 最大长方形
- 最大长方形。
- 最大长方形
- 割掉-----------------------------------------------割掉
- 也谈"正方形不是长方形"
- Problem H: 正方形、长方形、立方体
- Problem E: 正方形、长方形、立方体
- Problem C: 正方形、长方形、立方体
- Problem F: 正方形、长方形、立方体
- 最大正方形问题(DP)套路
- 最大正方形
- 最大正方形
- 最大正方形
- hibernate的配置
- 栈(链式存储)
- android自学问题一:dos命令行输入adb shell命令报错
- iOS开发系列--音频播放、录音、视频播放、拍照、视频录制
- 蓝桥杯 国王的烦恼 反向并查集
- 有趣问题:长方形不断分割掉最大正方形(5640)
- Linux中文件查找方法大全
- 二叉查找树模版
- iTunes Connect接入GameCenter配置
- Java关键字final、static使用总结
- android应用程序如何调用支付宝接口
- linux mkdir以及mount函数
- Linux Shell脚本编程--curl命令详解
- Python的yield用法