Untitled

 avatar
unknown
c_cpp
2 years ago
3.0 kB
6
Indexable
#include "bits/stdc++.h"
using namespace std;
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(x...)
#endif
 
struct Point {
 
    int x = 0, y = 0;
 
    Point(int _x, int _y) {
        x = _x;
        y = _y;
    }
 
};
 
struct Vector {
 
    int x = 0, y = 0;
 
    Vector(int _x, int _y) {
        x = _x;
        y = _y;
    }
 
    Vector(Point a) {
        x = a.x;
        y = a.y;
    }
 
    Vector(Point a, Point b) {
        x = b.x - a.x;
        y = b.y - a.y;
    }
 
    Vector operator+(const Vector &other) {
        return {x + other.x, y + other.y};
    }
 
    Vector operator-(const Vector &other) {
        return {x - other.x, y - other.y};
    }
 
    int operator*(const Vector &other) {
        return x * other.x + y * other.y;
    }
 
    int operator^(const Vector &other) {
        return x * other.y - other.x * y;
    }
 
};
 
int dist2(Point a, Point b) {
    return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
 
double dist(Point a, Point b) {
    return sqrt(dist2(a, b));
}
 
int len2(Vector v) {
    return v.x * v.x + v.y * v.y;
}
 
double len(Vector v) {
    return sqrt(len2(v));
}
 
double dist_point_seg(Point a, Point c, Point d) {
    Vector CD(c, d), CA(c, a), DC(d, c), DA(d, a);
    if (CD * CA <= 0) {
        return dist(a, c);
    } else if (DC * DA <= 0) {
        return dist(a, d);
    } else {
        return abs(CA ^ CD) / len(CD);
    }
}
 
double dist_point_ray(Point a, Point c, Point d) {
    Vector CD(c, d), CA(c, a), DC(d, c), DA(d, a);
    if (CD * CA <= 0) {
        return dist(a, c);
    } else {
        return abs(CA ^ CD) / len(CD);
    }
}
 
double dist_point_line(Point a, Point c, Point d) {
    Vector CD(c, d), CA(c, a);
    return abs(CA ^ CD) / len(CD);
}
 
bool seg_inter(Point a, Point b, Point c, Point d) {
    Vector AB(a, b), AC(a, c), AD(a, d), BA(b, a), BC(b, c), BD(b, d), CA(c, a), CB(c, b), CD(c, d), DA(d, a), DB(d, b), DC(d, c);
    if ((CA ^ CD) == 0 || (CB ^ CD) == 0 || (AC ^ AB) == 0 || (AD ^ AB) == 0) {
        return (AC * AD <= 0 || BC * BD <= 0 || CA * CB <= 0 || DA * DB <= 0);
    } else {
        if ((CA ^ CD) > 0) {
            if ((CB ^ CD) > 0) return false;
        } else {
            if ((CB ^ CD) < 0) return false;
        }
        if ((AC ^ AB) > 0) {
            if ((AD ^ AB) > 0) return false;
        } else {
            if ((AD ^ AB) < 0) return false;
        }
        return true;
    }
}
 
void solve() {
    cout.precision(10);
    cout << fixed;
 
    int xa, ya, xb, yb, xc, yc, xd, yd;
    cin >> xa >> ya >> xb >> yb >> xc >> yc >> xd >> yd;
 
    Point A(xa, ya), B(xb, yb), C(xc, yc), D(xd, yd);
     
    cout << (seg_inter(A, B, C, D) ? "Yes" : "No");
 
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int tests = 1;
    // cin >> tests;
    while (tests--) {
        solve();
    }
    return 0;
}
Editor is loading...