-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaek12781.py
50 lines (38 loc) · 1.23 KB
/
baek12781.py
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
from sys import stdin
x1, y1, x2, y2, x3, y3, x4, y4= map(int, stdin.readline().split(" "))
minx1, maxx1 = min(x1, x2), max(x1, x2)
miny1, maxy1 = min(y1, y2), max(y1, y2)
minx2, maxx2 = min(x3, x4), max(x3, x4)
miny2, maxy2 = min(y3, y4), max(y3, y4)
minlx, maxlx = max(minx1, minx2), min(maxx1, maxx2)
minly, maxly = max(miny1, miny2), min(maxy1, maxy2)
def cross(a, b):
ab = a[0] * b[1] - a[1] * b[0]
return ab
a1 = y2 - y1
b1 = x1 - x2
c1 = -y1 * b1 - x1 * a1
a2 = y4 - y3
b2 = x3 - x4
c2 = -y3 * b2 - x3 * a2
# a1x+b1y+c=0
# a2x+b2y+c=0
a = [a1, a2]
b = [b1, b2]
c = [c1, c2]
if cross(a, b):
if cross(a, b) > 0:
if cross(a, b)*minlx <= cross(b, c) <= cross(a, b)*maxlx and cross(a, b)*minly <= cross(c, a) <= cross(a, b)*maxly:
if cross(a, b) * minlx == cross(b, c) and cross(a, b)*minly == cross(c, a) or cross(a, b) * maxlx == cross(b, c) and cross(a, b) * maxly == cross(c, a):
print(0)
else:
print(1)
else:
print(0)
elif cross(a, b) < 0:
if cross(a, b)*minlx >= cross(b, c) >= cross(a, b)*maxlx and cross(a, b)*minly >= cross(c, a) >= cross(a, b)*maxly:
print(1)
else:
print(0)
else:
print(0)