dimuster

348 acmp

Oct 6th, 2022
796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.21 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define ld long double
  7. #define inf 9e18
  8. #define v vector
  9. #define min(a, b) (a < b ? a : b)
  10. #define max(a, b) (a > b ? a : b)
  11.  
  12.  
  13. struct Point {
  14.     int x, y;
  15. };
  16.  
  17. struct Vector {
  18.     Point b, e;
  19. };
  20.  
  21. Vector make_v(Point a, Point b) {
  22.     Vector res;
  23.     res.b = a;
  24.     res.e = b;
  25.     return res;
  26. }
  27.  
  28. struct Segment {
  29.     Point b, e;
  30. };
  31.  
  32. int cross_product(Vector a, Vector b) {
  33.     return (a.e.x - a.b.x)*(b.e.y - b.b.y) - (b.e.x - b.b.x)*(a.e.y - a.b.y);
  34. }
  35.  
  36. int scalar_vector_multiply(Vector a, Vector b) {
  37.     return (a.e.x - a.b.x)*(b.e.x - b.b.x) + (b.e.y - b.b.y)*(a.e.y - a.b.y);
  38. }
  39.  
  40. signed main(signed argc, char* argv[]) {
  41.     ios_base::sync_with_stdio(false);
  42.     cin.tie(NULL);
  43. //    cout.setf(ios::fixed);
  44. //    cout.precision(6);
  45. //    freopen("input.txt", "r", stdin);
  46. //    freopen("output.txt", "w", stdout);
  47.      
  48.     ld PI = atan(1) * 4;
  49.      
  50.      
  51.     Segment a, b;
  52.     cin >> a.b.x >> a.b.y >> a.e.x >> a.e.y >> b.b.x >> b.b.y >> b.e.x >> b.e.y;
  53.     bool is_one_line = !cross_product(make_v(a.b, a.e), make_v(b.b, b.e));
  54.     if (!is_one_line) {
  55.         int res1 = cross_product(make_v(a.b, a.e), make_v(a.b, b.b));
  56.         int res2 = cross_product(make_v(a.b, a.e), make_v(a.b, b.e));
  57.         int res3 = cross_product(make_v(b.b, b.e), make_v(b.b, a.b));
  58.         int res4 = cross_product(make_v(b.b, b.e), make_v(b.b, a.e));
  59.         if ((res1 >= 0 && res2 <= 0 || res1 <= 0 && res2 >= 0) && (res3 >= 0 && res4 <= 0 || res3 <= 0 && res4 >= 0)) {
  60.             cout << "Yes";
  61.         } else {
  62.             cout << "No";
  63.         }
  64.     } else {
  65.         if (cross_product(make_v(a.b, a.e), make_v(a.b, b.b)) == 0) {
  66.             int res1 = scalar_vector_multiply(make_v(a.b, b.b), make_v(a.b, b.e));
  67.             int res2 = scalar_vector_multiply(make_v(a.e, b.b), make_v(a.e, b.e));
  68.             int res3 = scalar_vector_multiply(make_v(b.b, a.b), make_v(b.b, a.e));
  69.             if (res1 <= 0 || res2 <= 0 || res3 <= 0) {
  70.                 cout << "Yes";
  71.             } else {
  72.                 cout << "No";
  73.             }
  74.         } else {
  75.             cout << "No";
  76.         }
  77.     }
  78.      
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment