|
| 1 | +import sys |
| 2 | + |
| 3 | +read = lambda: sys.stdin.readline().rstrip() |
| 4 | + |
| 5 | + |
| 6 | +class Problem: |
| 7 | + def __init__(self): |
| 8 | + self.x1, self.y1, self.x2, self.y2 = map(int, read().split()) |
| 9 | + self.x3, self.y3, self.x4, self.y4 = map(int, read().split()) |
| 10 | + |
| 11 | + def solve(self) -> None: |
| 12 | + a, b, c, d = (self.x1, self.y1), (self.x2, self.y2), (self.x3, self.y3), (self.x4, self.y4) |
| 13 | + ccw_ab, ccw_cd = self.ccw(a, b, c) * self.ccw(a, b, d), self.ccw(c, d, a) * self.ccw(c, d, b) |
| 14 | + |
| 15 | + result = ccw_ab <= 0 and ccw_cd <= 0 |
| 16 | + if ccw_ab == 0 and ccw_cd == 0: |
| 17 | + result = self.is_overlap(a, b, c, d) |
| 18 | + |
| 19 | + print(int(result)) |
| 20 | + |
| 21 | + def ccw(self, point1: tuple[int, int], point2: tuple[int, int], point3: tuple[int, int]) -> int: |
| 22 | + result = (point2[0] - point1[0]) * (point3[1] - point1[1]) - (point2[1] - point1[1]) * (point3[0] - point1[0]) |
| 23 | + return 0 if result == 0 else (result // abs(result)) |
| 24 | + |
| 25 | + def is_overlap(self, a: tuple[int, int], b: tuple[int, int], c: tuple[int, int], d: tuple[int, int]) -> bool: |
| 26 | + return ( |
| 27 | + min(a[0], b[0]) <= max(c[0], d[0]) |
| 28 | + and min(c[0], d[0]) <= max(a[0], b[0]) |
| 29 | + and min(a[1], b[1]) <= max(c[1], d[1]) |
| 30 | + and min(c[1], d[1]) <= max(a[1], b[1]) |
| 31 | + ) |
| 32 | + |
| 33 | + |
| 34 | +if __name__ == "__main__": |
| 35 | + Problem().solve() |
0 commit comments