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 } 
    我自倾杯,君且随意
  • 相关阅读:
    centos 7安装配置vsftpd
    lvs和haproxy机器必须注意的三个参数
    用python 脚本实现zabbix对java端口报警
    git的下载地址
    看的一篇很好的博客
    学习内容
    数组一些用法
    dom
    dom1
    for的基础
  • 原文地址:https://www.cnblogs.com/nicetomeetu/p/5270332.html
Copyright © 2011-2022 走看看