fork(2) download
  1. #include <cstdio>
  2. #include <algorithm>
  3.  
  4. //check common interval existence
  5. bool range(int n1, int n2, int n3, int n4){
  6. int min1 = n1, max1 = n2, min2 = n3, max2 = n4;
  7. if ( n1 > n2 ) std::swap(min1, max1);
  8. if ( n3 > n4 ) std::swap(min2, max2);
  9. return !( min2 > max1 || max2 < min1 );
  10. }
  11.  
  12. int main()
  13. {
  14. int A, B, C, D; //coords
  15. int tA, tB, tC, tD; //time
  16.  
  17. scanf("%d %d %d %d", &A, &tA, &B, &tB);
  18. scanf("%d %d %d %d", &C, &tC, &D, &tD);
  19.  
  20. if ( range( A, B, C, D ) && range( tA, tB, tC, tD ) )
  21. {
  22. //common line equation Ax + By + C == 0 coefficients
  23. int a1 = tA-tB, b1 = B-A, c1 = A*tB - B*tA;
  24. int a2 = tC-tD, b2 = D-C, c2 = C*tD - D*tC;
  25.  
  26. int r1 = a1*C + b1*tC + c1;
  27. int r2 = a1*D + b1*tD + c1;
  28. int r3 = a2*A + b2*tA + c2;
  29. int r4 = a2*B + b2*tB + c2;
  30.  
  31. //if both dots lie in different semiareas, or at least one of them lies on the segment
  32. if( r1*r2 <= 0 && r3*r4 <= 0 )
  33. {
  34. printf("Yes\n");
  35. return 0;
  36. }
  37. }
  38. printf("No\n");
  39. return 0;
  40. }
Success #stdin #stdout 0s 3300KB
stdin
0 0
1 1
0 0
1 2
stdout
Yes