# BOJ - 6439 - 교차

Updated:

``````import sys

def isCCW(x1, y1, x2, y2, x3, y3):
ret = (x1 * y2 + x2 * y3 + x3 * y1) - (y1 * x2 + y2 * x3 + y3 * x1)
if ret < 0: return -1
elif ret > 0:  return 1
else: return 0

def isCross(x1, y1, x2, y2, x3, y3, x4, y4):
if (
isCCW(x1, y1, x2, y2, x3, y3) * isCCW(x1, y1, x2, y2, x4, y4) <= 0 and
isCCW(x3, y3, x4, y4, x1, y1) * isCCW(x3, y3, x4, y4, x2, y2) <= 0):
if (x1 < x3 and x1 < x4 and x2 < x3 and x2 < x4) or \
(x3 < x1 and x3 < x2 and x4 < x1 and x4 < x2): return False

if (y1 < y3 and y1 < y4 and y2 < y3 and y2 < y4) or \
(y3 < y1 and y3 < y2 and y4 < y1 and y4 < y2): return False
return True
return False

def solution():
for _ in range(T):
xs, ys, xe, ye, xl, yt, xr, yb = map(int, sys.stdin.readline().split())

r1 = [min(xl, xr), min(yt, yb)]
r2 = [min(xl, xr), max(yt, yb)]
r3 = [max(xl, xr), min(yt, yb)]
r4 = [max(xl, xr), max(yt, yb)]

if isCross(xs, ys, xe, ye, r1, r1, r2, r2) or \
isCross(xs, ys, xe, ye, r2, r2, r4, r4) or \
isCross(xs, ys, xe, ye, r4, r4, r3, r3) or \
isCross(xs, ys, xe, ye, r3, r3, r1, r1): print("T")
else:
if (r1 < xs and r1 < xe and xs < r3 and xe < r3) and \
(r1 < ys and r1 < ys and ys < r4 and ye < r4): print("T")
else: print("F")

solution()
``````

https://www.acmicpc.net/problem/6439

Categories:

Updated: