Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long
- #define ld long double
- #define inf 9e18
- #define v vector
- #define min(a, b) (a < b ? a : b)
- #define max(a, b) (a > b ? a : b)
- struct Point {
- int x, y;
- };
- struct Vector {
- Point b, e;
- };
- Vector make_v(Point a, Point b) {
- Vector res;
- res.b = a;
- res.e = b;
- return res;
- }
- struct Segment {
- Point b, e;
- };
- int cross_product(Vector a, Vector b) {
- 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);
- }
- int scalar_vector_multiply(Vector a, Vector b) {
- 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);
- }
- signed main(signed argc, char* argv[]) {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- // cout.setf(ios::fixed);
- // cout.precision(6);
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- ld PI = atan(1) * 4;
- Segment a, b;
- 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;
- bool is_one_line = !cross_product(make_v(a.b, a.e), make_v(b.b, b.e));
- if (!is_one_line) {
- int res1 = cross_product(make_v(a.b, a.e), make_v(a.b, b.b));
- int res2 = cross_product(make_v(a.b, a.e), make_v(a.b, b.e));
- int res3 = cross_product(make_v(b.b, b.e), make_v(b.b, a.b));
- int res4 = cross_product(make_v(b.b, b.e), make_v(b.b, a.e));
- if ((res1 >= 0 && res2 <= 0 || res1 <= 0 && res2 >= 0) && (res3 >= 0 && res4 <= 0 || res3 <= 0 && res4 >= 0)) {
- cout << "Yes";
- } else {
- cout << "No";
- }
- } else {
- if (cross_product(make_v(a.b, a.e), make_v(a.b, b.b)) == 0) {
- int res1 = scalar_vector_multiply(make_v(a.b, b.b), make_v(a.b, b.e));
- int res2 = scalar_vector_multiply(make_v(a.e, b.b), make_v(a.e, b.e));
- int res3 = scalar_vector_multiply(make_v(b.b, a.b), make_v(b.b, a.e));
- if (res1 <= 0 || res2 <= 0 || res3 <= 0) {
- cout << "Yes";
- } else {
- cout << "No";
- }
- } else {
- cout << "No";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment