zoukankan      html  css  js  c++  java
  • BestCoder Round #75 1001

    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
     

    切正方形蛋糕,两条边轮流互减

     1 #include <iostream>
     2 #include <cstdio>
     3 using namespace std;
     4 #define LL long long
     5 int m,n,t;
     6 LL ans;
     7 int main(){
     8     scanf("%d",&t);
     9     while(t--){
    10         scanf("%d%d",&m,&n);
    11         ans=0;
    12         while(m>0&&n>0){
    13             if(m>n) swap(m,n);
    14             n-=m;
    15             ans++;
    16         }
    17         cout<<ans<<endl;
    18     }
    19 } 
    我自倾杯,君且随意
  • 相关阅读:
    centos6和centos7网卡修改
    centos7.4编译安装LNMP
    centos7yum安装LNMP
    jira搭建
    centos6.9编译安装LNMP
    监控命令命令
    linux设置命令历史的时间戳
    zabbix3.0安装
    Mysql(centos7) 主从搭建
    Android 利用剪切板(clipboardManager )实现数据传递
  • 原文地址:https://www.cnblogs.com/nicetomeetu/p/5270332.html
Copyright © 2011-2022 走看看