Advertisement
OIQ

348

OIQ
Oct 31st, 2019
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4.  
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11.     long long ax1, ay1, ax2, ay2, bx1, by1, bx2, by2;
  12.  
  13.     cin >> ax1 >> ay1 >> ax2 >> ay2 >> bx1 >> by1 >> bx2 >> by2;
  14.     int sign1, sign2, sign3, sign4;
  15.  
  16.     long long s1 = (ax2 - ax1) * (by1 - ay1) - (bx1 - ax1) * (ay2 - ay1);
  17.     long long s2 = (ax2 - ax1) * (by2 - ay2) - (bx2 - ax1) * (ay2 - ay1);
  18.     long long s3 = (bx2 - bx1) * (ay1 - by1) - (ax1 - bx1) * (by2 - by1);
  19.     long long s4 = (bx2 - bx1) * (ay2 - by1) - (ax2 - bx1) * (by2 - by1);
  20.  
  21.     if (ax1 > ax2) {
  22.         swap(ax1, ax2);
  23.     }
  24.  
  25.     if (bx1 > bx2) {
  26.         swap(bx1, bx2);
  27.     }
  28.  
  29.     int dx1 = max(ax1, bx1);
  30.     int dx2 = min(ax2, bx2);
  31.  
  32.     if (ay1 > ay2) {
  33.         swap(ay1, ay2);
  34.     }
  35.  
  36.     if (by1 > by2) {
  37.         swap(by1, by2);
  38.     }
  39.  
  40.     int dy1 = max(ay1, by1);
  41.     int dy2 = min(ay2, by2);
  42.  
  43.     if (s1 < 0)
  44.         sign1 = -1;
  45.     else if (s1 == 0)
  46.         sign1 = 0;
  47.     else sign1 = 1;
  48.     if (s2 < 0)
  49.         sign2 = -1;
  50.     else if (s1 == 0)
  51.         sign2 = 0;
  52.     else sign2 = 1;
  53.     if (s3 < 0)
  54.         sign3 = -1;
  55.     else if (s1 == 0)
  56.         sign3 = 0;
  57.     else sign3 = 1;
  58.     if (s4 < 0)
  59.         sign4 = -1;
  60.     else if (s1 == 0)
  61.         sign4 = 0;
  62.     else sign4 = 1;
  63.  
  64.  
  65.     if (sign1 * sign2 == 0 && sign3 * sign4 == 0 && dx2 >= dx1 && dy2 >= dy1) {
  66.         cout << "Yes";
  67.         return 0;
  68.     }
  69.  
  70.  
  71.     if (sign1 * sign2 < 0 && sign3 * sign4 < 0)
  72.         cout << "Yes";
  73.     else cout << "No";
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement