fork(2) download
  1. #include <cmath>
  2. #include <iostream>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. #define __TAK__ { cout << __LINE__ << "TAK\n"; continue; }
  7. #define __NIE__ { cout << __LINE__ << "NIE\n"; continue; }
  8. #define __UND__ { cout << __LINE__ << "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 ( d < b ) __NIE__;
  26. if ( a == c || b == d ) __NIE__;
  27. if ( a > c && b > d ) __TAK__;
  28. if ( a + b < c + d ) __NIE__;
  29. if ( a * b < c * d ) __NIE__;
  30.  
  31. // advanced tests
  32. if ( hypot( a, b ) < hypot( c, d ) ) __NIE__;
  33. if ( (double)b/a < (double)d/c ) __NIE__;
  34.  
  35. // part of solution from the past
  36. double _c, _d, alfa;
  37. alfa = atan2(b, a);
  38. _c = c * sin(alfa) + d * cos(alfa);
  39. _d = c * cos(alfa) + d * sin(alfa);
  40. if( (a > _c && b > _d) ||
  41. (a > _d && b > _c) ) __TAK__;
  42.  
  43. // mysterious formula from book
  44. {
  45. double x;
  46. x = 2 * a;
  47. x *= c * d;
  48. x /= ( c*c + d*d );
  49.  
  50. double x_;
  51. x_ = ( c*c - d*d );
  52. x_ *= sqrt( c*c - a*a + d*d );
  53. x_ /= ( c*c + d*d );
  54.  
  55. x += x_;
  56. if ( c > a && b > x ) __TAK__ else __NIE__;
  57. }
  58. }
  59. }
Success #stdin #stdout 0s 4532KB
stdin
4
7 10 3 5
3 6 4 2
4 10 9 1
8 10 2 10
stdout
27TAK
27TAK
27TAK
26NIE