HDU 5640 King's Cake【模拟】

题意:

给定长方形,每次从中切去一个最大的正方形,问最终可以得到多少正方形。

分析:

过程类似求gcd,每次减去最小的边即可。

代码:

#include <cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int main (void)
{
    int T;cin>>T;
    int n, m;
    while(T--){
        cin>>n>>m;
        int cnt = 0;
        int t;
        while(n!=m && n && m){
            cnt++;
            if(m<n) n -= m;
            else m-=n;
        }
        cout<<cnt+1<<endl;
    }
}
原文地址:https://www.cnblogs.com/Tuesdayzz/p/5758740.html