fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. bool first_enclose_second(double a, double b, double c, double d)
  5. {
  6. if (a < b)
  7. std::swap(a, b);
  8.  
  9. if (c < d)
  10. std::swap(c, d);
  11.  
  12. if (c <= a)
  13. return d <= b;
  14.  
  15. const auto ss = c * c + d * d;
  16. const auto p = std::sqrt(ss - b * b);
  17. const auto q = std::sqrt(ss - a * a);
  18.  
  19. return a * b - p * q >= c * d * 2;
  20. }
  21.  
  22. int main()
  23. {
  24. std::cout << std::boolalpha;
  25. std::cout << first_enclose_second(2, 2, 1, 1) << std::endl; // true
  26. std::cout << first_enclose_second(1, 1, 2, 2) << std::endl; // false
  27. std::cout << first_enclose_second(5, 5, 5.5, 1) << std::endl; // true
  28. }
  29.  
  30.  
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
true
false
true