天天看点

HDU5640 King's Cake(简单模拟)

题目链接

题意:给你n*m的矩形,每次切出一个正方形,问最多可以切几个

解法:模拟一下

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <set>
#include <vector>
#include <map>
using namespace std;


const int maxn=;
const int inf=<<;
#define LL long long
#define cl(a,b) memset(a,b,sizeof(a))

int ans;
void dfs(int n,int m){
    if(n<=||m<=)return ;
    int x=min(n,m);
    int y=max(n,m);
    ans+=y/x;
    dfs(x,y%x);
}
int main(){
    int T;
    scanf("%d",&T);
    while(T--){
        int n,m;
        scanf("%d%d",&n,&m);
        ans=;
        dfs(n,m);
        printf("%d\n",ans);
    }
    return ;
}