-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path17387_ccw.cpp
54 lines (52 loc) · 1.15 KB
/
17387_ccw.cpp
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
// 210319 #17387 ¼±ºÐ ±³Â÷ 2 Gold II
// operator overloading is important
#include <iostream>
using namespace std;
typedef long long ll;;
struct Point {
ll x, y;
bool operator<(const Point& O) {
if (x != O.x)
return x < O.x;
return y < O.y;
}
bool operator==(const Point& O) {
if (x == O.x && y == O.y)
return true;
return false;
}
};
Point p[4];
ll ccw(const Point& p1, const Point& p2, const Point& p3) {
ll ret = (p1.x * p2.y + p2.x * p3.y + p3.x * p1.y)
- (p1.y * p2.x + p2.y * p3.x + p3.y * p1.x);
if (ret > 0) return 1;
else if (ret < 0) return -1;
else return 0;
}
int main() {
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
for (int i = 0; i < 4; i++) {
cin >> p[i].x >> p[i].y;
}
ll ans1 = ccw(p[0], p[1], p[2]) * ccw(p[0], p[1], p[3]);
ll ans2 = ccw(p[2], p[3], p[0]) * ccw(p[2], p[3], p[1]);
if (ans1 <= 0 && ans2 <= 0) {
if (!ans1 && !ans2) {
if (p[1] < p[0])
swap(p[0], p[1]);
if (p[3] < p[2])
swap(p[2], p[3]);
if ((p[0] < p[3] || p[0] == p[3]) && (p[2] < p[1] || p[2] == p[1]))
cout << 1 << "\n";
else
cout << 0 << "\n";
}
else
cout << 1 << "\n";
}
else
cout << 0 << "\n";
}