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(1n,m10000) . 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(T1000), the number of the testcases.

For each testcase, the first line and the only line contains two positive numbers n,m(1n,m10000).
 

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: 960
 
 Submissions: 1572
 Time Limit: 2000/1000 MS (Java/Others)
 
 Memory Limit: 65536/65536 K (Java/Others)
问题描述
阅兵式前一天,是国王的生日,大臣们为他准备了一个 n \times m(1\le n, m \le 10000)n×m(1n,m10000) 的蛋糕。他准备切蛋糕,但他切蛋糕有奇奇怪怪的癖好,他每次只切一刀,切下一个正方形蛋糕。请问它最多能切出多少个正方形蛋糕?
输入描述
第一行一个整数表示测试组数:T(0 < T\le1000)T(0<T1000) 。每组数据占一行,每行两个整数 n \times m(1\le n, m \le 10000)n×m(1n,m10000),表示蛋糕的大小。
输出描述
TT 行,每行一个整数表示最多能切出的正方形蛋糕数量。
输入样例
22 32 5
输出样例
34
Hint
对于第一组数据,可切出一个 2\times22×2, 两个 1\times 11×1,共 33 个。对于第一组数据,可切出两个 2\times22×2, 两个 1\times 11×1,共 44 个。
#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