HDU 5640 King's Cake

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

Recommend

wange2014

题目大意:阅兵式前一天,是国王的生日,大臣们为他准备了一个 n *m(1<=n, m<=10000)的蛋糕。他准备切蛋糕,但他切蛋糕有奇奇怪怪的癖好,他每次只切一刀,切下一个正方形蛋糕。请问它最多能切出多少个正方形蛋糕?

思路:看图

#include <iostream>
#include <cstdio>
using namespace std;
int t;
int f(int m, int n)
{
        if(m<n) return (f(n,m));
        t += m/n;
        if(m%n==0) return 0;
        f(n,m%n);
}
int main()
{
        int m, n, T;
        scanf("%d", &T);
        while(T--)
        {
        scanf("%d%d", &m, &n);
        t=0;
        f(m, n);
        printf("%d\n", t);
        }
        return 0;
}

HDU 5640 King's Cake

时间: 2024-10-05 23:16:16

HDU 5640 King's Cake的相关文章

hdu 5640 King&#39;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

hdu 5641 King&#39;s Phone(暴力模拟题)

Problem Description In a military parade, the King sees lots of new things, including an Andriod Phone. He becomes interested in the pattern lock screen. The pattern interface is a 3×3 square lattice, the three points in the first line are labeled as

hdu 5642 King&#39;s Order

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5642 题意:给出一个n,问一个长度为n的只含有小写字母的序列中,满足其中不含有超过3个连续相同字母的序列的个数有多少. 思路: 设dp[i][j],表示序列第i位为字母j的合法序列的个数.sum[i]表示长度为i的序列有多少个. 假设第i位为字母'a',dp[i][j]就是sum[i-1]*1-不合法的情况. 不合法的情况就是sum[i-4] - dp[i-4][j]. sum[i-4]表示已经计算

HDU 4337 King Arthur&#39;s Knights 找出一条哈密顿回路

n个点m条无向边 输出一条哈密顿回路 #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 155; int n, m; bool mp[N][N]; int S, T, top, Stack[N]; bool vis[N]; void _reverse(int l,int r) { while (l<r) swap(Stack[l++

hdu 4454 Stealing a Cake(三分)

题目链接:hdu 4454 Stealing a Cake 题目大意:给定一个起始点s,一个圆形,一个矩形.现在从起点开始,移动到圆形再移动到矩形,求最短距离. 解题思路:在圆周上三分即可.即对角度[0,2*pi]三分,计算点和矩形的距离可以选点和矩形四条边的距离最短值. #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std

HDU 5643 King&#39;s Game | 约瑟夫环变形

经典约瑟夫环 1 int f[N] ={ 0 }; 2 for(int i=2; i<=n; i++) 3 { 4 f[i] = (f[i-1] + k) % i; 5 } 变形:k是变化的 #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm> #include <stdlib.h> #include <queue> #in

HDU 5642 King&#39;s Order(数位DP)

题目链接:点击打开链接 题意:要求你生成一个合法的字符串, 由小写字母a~z组成, 相同字母相邻出现不能超过3个, 求有多少种组合. 思路:数位DP来做, 用d[i][j][k]表示处理完前i个字母, 第i-1个字母为j,已经连续出现了k次的方法数. 然后每次转移就很简单了, 继续选择字母j(if(k < 3)), 或者换其他的. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #inc

HDU 5640

King's Cake Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 188    Accepted Submission(s): 159 Problem Description It is the king's birthday before the military parade . The ministers prepared a

HDU 4337 King Arthur&amp;#39;s Knights 它输出一个哈密顿电路

n积分m文章无向边 它输出一个哈密顿电路 #include <cstdio> #include <cstring> #include <iostream> using namespace std; const int N = 155; int n, m; bool mp[N][N]; int S, T, top, Stack[N]; bool vis[N]; void _reverse(int l,int r) { while (l<r) swap(Stack[l