fork(3) download
  1. #include<iostream>
  2. #include<complex>
  3. using namespace std;
  4.  
  5. typedef complex<double> point;
  6.  
  7. #define vec(a,b) (b)-(a)
  8. #define dot(a,b) (conj(a)*(b)).real()
  9. #define cross(a,b) (conj(a)*(b)).imag()
  10. #define lensqr(a) dot(a,a)
  11. #define EPS 1e-9
  12.  
  13. double N, xstr, ystr, xend, yend, xtopLeft, ytopLeft, xbottomRight, ybottomRight;
  14.  
  15. bool Lines_intersect(const point &a, const point &b, const point &p, const point &q, point &ret) {
  16. double d1 = cross(vec(a,p),vec(a,b)),
  17. d2 = cross(vec(a,q),vec(a,b));
  18. ret = (d1 * q - d2 * p) / (d1 - d2);
  19. return fabs(d1 - d2) > EPS;
  20. }
  21.  
  22. bool pointOnRay(const point &a, const point &b, const point &p) {
  23. return cross(vec(a,b),vec(a,p)) < EPS
  24. && cross(vec(a,b),vec(a,p)) > -EPS
  25. && dot(vec(a,b),vec(a,p)) > -EPS;
  26. }
  27.  
  28. bool pointOnSegment(const point &a, const point &b, const point &p) {
  29. if (lensqr(vec(a,b)) < EPS)
  30. return lensqr(vec(a,p)) < EPS;
  31. return pointOnRay(a, b, p) && pointOnRay(b, a, p);
  32. }
  33.  
  34. int main() {
  35. cin >> N;
  36. point ret;
  37. while (N--) {
  38. cin >> xstr >> ystr >> xend >> yend >> xtopLeft >> ytopLeft >> xbottomRight >> ybottomRight;
  39.  
  40. if (Lines_intersect(point(xstr, ystr), point(xend, yend), point(xtopLeft, ytopLeft), point(xtopLeft, ybottomRight), ret)
  41. && pointOnSegment(point(xstr, ystr), point(xend, yend), ret)
  42. && pointOnSegment(point(xtopLeft, ytopLeft), point(xtopLeft, ybottomRight), ret)) {
  43. cout << "T" << endl;
  44. continue;
  45. }
  46.  
  47. if (Lines_intersect(point(xstr, ystr), point(xend, yend), point(xtopLeft, ytopLeft), point(xbottomRight, ytopLeft), ret)
  48. && pointOnSegment(point(xstr, ystr), point(xend, yend), ret)
  49. && pointOnSegment(point(xtopLeft, ytopLeft), point(xbottomRight, ytopLeft), ret)) {
  50. cout << "T" << endl;
  51. continue;
  52. }
  53.  
  54. if (Lines_intersect(point(xstr, ystr), point(xend, yend), point(xbottomRight, ytopLeft), point(xbottomRight, ybottomRight), ret)
  55. && pointOnSegment(point(xstr, ystr), point(xend, yend), ret)
  56. && pointOnSegment(point(xbottomRight, ytopLeft), point(xbottomRight, ybottomRight), ret)) {
  57. cout << "T" << endl;
  58. continue;
  59. }
  60.  
  61. if (Lines_intersect(point(xstr, ystr), point(xend, yend), point(xtopLeft, ybottomRight), point(xbottomRight, ybottomRight), ret)
  62. && pointOnSegment(point(xstr, ystr), point(xend, yend), ret)
  63. && pointOnSegment(point(xtopLeft, ybottomRight), point(xbottomRight, ybottomRight), ret)) {
  64. cout << "T" << endl;
  65. continue;
  66. }
  67.  
  68. if (xstr <= (xtopLeft > xbottomRight ? xtopLeft : xbottomRight)
  69. && xstr >= (xtopLeft < xbottomRight ? xtopLeft : xbottomRight)
  70. && ystr <= (ytopLeft > ybottomRight ? ytopLeft : ybottomRight)
  71. && ystr >= (ytopLeft < ybottomRight ? ytopLeft : ybottomRight)) {
  72. cout << "T" << endl;
  73. continue;
  74. }
  75. cout << "F" << endl;
  76. }
  77. return 0;
  78. }
Success #stdin #stdout 0.01s 2820KB
stdin
1
0 0 3 3 0 0 3 3
stdout
T