HDU 5640 King's Cake

Description

一块蛋糕,每次只能切正方形,问最多能切多少块?

Algorithm

模拟切的过程,每次改变长宽

Code

#include <iostream>
using namespace std;
int main()
{
  int t;
  cin >> t;
  for (int i = 0; i < t; i++)
  {
    int n, m;
    cin >> n >> m;
    int ans = 0;
    while (n > 0 && m > 0)
    {
      if (n > m) n -= m; else m -= n;
      ans++;
    }
    cout << ans << endl;
  }
}

你可能感兴趣的:(HDU 5640 King's Cake)