hdoj King's Cake 5640 (模拟)
来源:互联网 发布:淘宝店铺怎么改折扣价 编辑:程序博客网 时间:2024/05/18 16:40
King's Cake
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 411 Accepted Submission(s): 339
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 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
34hint:For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$King's Cake
Accepts: 960Submissions: 1572Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 65536/65536 K (Java/Others)问题描述阅兵式前一天,是国王的生日,大臣们为他准备了一个 n×m(1≤n,m≤10000) 的蛋糕。他准备切蛋糕,但他切蛋糕有奇奇怪怪的癖好,他每次只切一刀,切下一个正方形蛋糕。请问它最多能切出多少个正方形蛋糕?
输入描述第一行一个整数表示测试组数:T(0<T≤1000) 。每组数据占一行,每行两个整数 n×m(1≤n,m≤10000),表示蛋糕的大小。输出描述共 T 行,每行一个整数表示最多能切出的正方形蛋糕数量。
输入样例22 32 5输出样例34Hint对于第一组数据,可切出一个 2×2, 两个 1×1,共 3 个。对于第一组数据,可切出两个 2×2, 两个 1×1,共 4 个。#include<stdio.h>#include<string.h>#include<algorithm>#include<iostream>#include<map>#define INF 0x3f3f3f3f#define ull unsigned long long#define IN __int64#define ll long longusing namespace std;int main(){ int t,n,m; int i,j,k; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); if(n>m) { int kk=n; n=m; m=kk; } int nn=n; int mm=m; k=0; while(nn&&mm) { k++; mm=n; nn=m-n; if(nn>mm) { int kk=nn; nn=mm; mm=kk; } n=nn;m=mm; } printf("%d\n",k); } return 0;}
0 0
- hdoj King's Cake 5640 (模拟)
- HDOJ 5640 king's cake
- HDOJ 5640 King's Cake
- hdoj-5640-King's Cake
- hdu 5640 King's Cake(模拟)
- HDOJ 5640-King's Cake【数学】
- HDU 5640 King's Cake [模拟]
- HDU 5640 King's Cake【模拟】
- HDU5640 King's Cake(简单模拟)
- BestCoder Round #75-King's Cake(模拟)
- HDU 5640 King's Cake
- HDU 5640 King's Cake
- HDU 5640 King's Cake
- HDU 5640 King's Cake
- HDU 5640 King's Cake
- HDU 5640 King's Cake
- hdu 5640 King's Cake
- HDU 5640:King's Cake【几何】
- 3d引擎列表
- Zbrush 4R7 P3中给类模型怎么快速隐藏
- 设计模式_原型模式
- 264. Ugly Number II LeetCode
- java程序为什么无须delete语句进行内存回收
- hdoj King's Cake 5640 (模拟)
- Win7下配置Oracle数据源
- Swift - 添加、修改、删除通讯录联系人
- 面向对象基础知识
- 串行通信、并行通信、同步通信、异步通信
- TableView 插入表格和删除表格
- ArrayList、LinkedList和Vector 的区别
- AIX调整swap大小
- rel_exp - IS BOUND