zoukankan      html  css  js  c++  java
  • 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 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
    2
    2 3
    2 5
     
    Sample Output
    3
    4
    hint: For the first testcase you can divide the into one cake of $2 imes2$ , 2 cakes of $1 imes 1$
     
    Source
     
    题意:n*m的蛋糕 每次只能 切一刀 并且切下来的是正方形 问 最多能切成几个正方形
    题解: 模拟过程就可以了
     1 #include<cstring>
     2 #include<cstdio>
     3 #include<map>
     4 #include<queue>
     5 #include<stack>
     6 #include<set>
     7 using namespace std;
     8 int t;
     9 int n,m;
    10 int main()
    11 {
    12     scanf("%d",&t);
    13     for(int i=1;i<=t;i++)
    14     {
    15         scanf("%d %d",&n,&m);
    16         int t;
    17         int ans=0;
    18         int minx=min(n,m);
    19         if(n>m)
    20         {
    21             t=n;
    22             n=m;
    23             m=t;
    24         }
    25         while(n!=m)
    26         {
    27             n=m-minx;
    28             m=minx;
    29             if(n>m)
    30         {
    31             t=n;
    32             n=m;
    33             m=t;
    34         }
    35             minx=min(n,m);
    36             ans++;
    37         }
    38         printf("%d
    ",ans+1);
    39 
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    Python
    Python 学习之路
    Python 学习之路
    Python 学习之路
    Python 学习之路
    Python 学习之路
    Python 学习之路
    Python学习之路
    Python 学习之路
    Python 学习之路
  • 原文地址:https://www.cnblogs.com/hsd-/p/5271713.html
Copyright © 2011-2022 走看看