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
  • 相关阅读:
    2020软件工程个人作业06————软件工程实践总结作业
    2020软件工程作业01
    班级博客V2.1版本更新日志
    博客园班级手机版
    班级帮助文档
    问题累计
    2020 软件工程作业06
    2020 软件工程作业04
    2020 软件工程作业03
    2020软件工程02
  • 原文地址:https://www.cnblogs.com/hsd-/p/5271713.html
Copyright © 2011-2022 走看看