fork download
  1. #include <cmath>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. #define __TAK__ { cout << "TAK\n"; continue; }
  7. #define __NIE__ { cout << "NIE\n"; continue; }
  8. #define __UND__ { cout << "UND\n"; continue; }
  9.  
  10. int main()
  11. {
  12. int problems;
  13. cin >> problems;
  14.  
  15. while ( problems-- )
  16. {
  17. int a, b, c, d;
  18. cin >> a >> b >> c >> d;
  19.  
  20. // normalisation
  21. if ( a < b ) swap( a, b );
  22. if ( c < d ) swap( c, d );
  23.  
  24. // basic tests
  25. if ( a == c || b <= d ) __NIE__;
  26. if ( a > c && b > d ) __TAK__;
  27. if ( a + b < c + d ) __NIE__;
  28. if ( a * b < c * d ) __NIE__;
  29.  
  30. // advanced tests
  31. if ( hypot( a, b ) < hypot( c, d ) ) __NIE__;
  32. if ( (double)b/a < (double)d/c ) __NIE__;
  33.  
  34. // part of solution from the past
  35. double _c, _d, alfa;
  36. alfa = atan2(b, a);
  37. _c = c * sin(alfa) + d * cos(alfa);
  38. _d = c * cos(alfa) + d * sin(alfa);
  39. if( (a > _c && b > _d) ||
  40. (a > _d && b > _c) ) __TAK__;
  41.  
  42. // mysterious formula from book
  43. {
  44. double x;
  45. x = 2 * a;
  46. x *= c * d;
  47. x /= ( c*c + d*d );
  48.  
  49. double x_;
  50. x_ = ( c*c - d*d );
  51. x_ *= sqrt( c*c - a*a + d*d );
  52. x_ /= ( c*c + d*d );
  53.  
  54. x += x_;
  55. if ( c > a && b > x ) __TAK__ else __NIE__;
  56. }
  57. }
  58. }
  59.  
Success #stdin #stdout 0s 4480KB
stdin
  8
 10 11   7  8
  8  7  10 11
100 50 105  9
 81 59  88 13
  7 10   3  5
  3  6   4  2
  4 10   9  1
  8 10   2 10
stdout
TAK
NIE
TAK
TAK
TAK
TAK
TAK
NIE