[UVa] 839 - Not so Mobile

題目

Link: UVa 839 - Not so Mobile

Code

C++

#include <iostream>

int recursion();

int main()
{
  int cases;
  std::ios::sync_with_stdio(false);
  std::cin >> cases;
  while (cases--)
  {
    if(recursion()) std::cout << "YES\n";
    else std::cout << "NO\n";
    if (cases) std::cout << std::endl;
  }
  return 0;
}

int recursion()
{
  int w1, d1, w2, d2;
  std::cin >> w1 >> d1 >> w2 >> d2;
  if (w1 == 0) w1 = recursion();
  if (w2 == 0) w2 = recursion();
  if (w1 && w2 && w1 * d1 == w2 * d2) return w1 + w2;
  return 0;
}

Show Comments