[Link] https://www.acmicpc.net/problem/17387
## Point: Line AB and CD : ccw(ABC) and ccw(ABD) ## if(ccw(ABC) == ccw(ABD) == 0) compare the range A B C D, C D A B
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <stack>
#include <cmath>
// #include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define command_param int argc, char *argv[]
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i < n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
#define ll long long
#define endl "\n"
#define nulls '\0'
#define dkdk " "
const int MAX = 2002;
const int INF = 987654321;
int n;
vector<pair<int,int>> points;
int ccw(pair<int, int> line[2], pair<int,int> p) {
int dx1 = line[1].first - line[0].first, dy1 = line[1].second - line[0].second;
int dx2 = p.first - line[0].first, dy2 = p.second - line[0].second;
ll result = (ll)dx1*dy2 - (ll)dy1*dx2;
return result == 0 ? 0 : (result > 0 ? 1 : -1);
}
int main() {
FASTIO;
pair<int, int> l1[2], l2[2];
cin >> l1[0].first >> l1[0].second >> l1[1].first >> l1[1].second >> l2[0].first >> l2[0].second >> l2[1].first >> l2[1].second;
bool meet = true;
int c1 = ccw(l1, l2[0]), c2 = ccw(l1, l2[1]);
if(c1 == c2) {
if(c1 != 0) meet = false;
else if(
min(l1[0].first, l1[1].first) > max(l2[0].first, l2[1].first) || min(l2[0].first, l2[1].first) > max(l1[0].first, l1[1].first) ||
min(l1[0].second, l1[1].second) > max(l2[0].second, l2[1].second) || min(l2[0].second, l2[1].second) > max(l1[0].second, l1[1].second)
)
meet = false;
}
if(meet) {
c1 = ccw(l2, l1[0]), c2 = ccw(l2, l1[1]);
if(c1 == c2) {
if(c1 != 0) meet = false;
}
}
cout << (meet ? 1 : 0);
return 0;
}