[Gold II] Title: 선분 교차 2, Time: 36 ms, Memory: 32412 KB -BaekjoonHub

This commit is contained in:
SSUM
2025-03-05 14:41:09 +09:00
parent 851bef2b95
commit 7c3e6de203
2 changed files with 56 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
# [Gold II] 선분 교차 2 - 17387
[문제 링크](https://www.acmicpc.net/problem/17387)
### 성능 요약
메모리: 32412 KB, 시간: 36 ms
### 분류
많은 조건 분기, 기하학, 선분 교차 판정
### 제출 일자
2025년 3월 5일 14:40:51
### 문제 설명
<p>2차원 좌표 평면 위의 두 선분 L<sub>1</sub>, L<sub>2</sub>가 주어졌을 때, 두 선분이 교차하는지 아닌지 구해보자. 한 선분의 끝 점이 다른 선분이나 끝 점 위에 있는 것도 교차하는 것이다.</p>
<p>L<sub>1</sub>의 양 끝 점은 (x<sub>1</sub>, y<sub>1</sub>), (x<sub>2</sub>, y<sub>2</sub>), L<sub>2</sub>의 양 끝 점은 (x<sub>3</sub>, y<sub>3</sub>), (x<sub>4</sub>, y<sub>4</sub>)이다.</p>
### 입력
<p>첫째 줄에 L<sub>1</sub>의 양 끝 점 x<sub>1</sub>, y<sub>1</sub>, x<sub>2</sub>, y<sub>2</sub>가, 둘째 줄에 L<sub>2</sub>의 양 끝 점 x<sub>3</sub>, y<sub>3</sub>, x<sub>4</sub>, y<sub>4</sub>가 주어진다.</p>
### 출력
<p>L<sub>1</sub>과 L<sub>2</sub>가 교차하면 1, 아니면 0을 출력한다.</p>

View File

@@ -0,0 +1,26 @@
import sys
input = sys.stdin.readline
x1, y1, x2, y2 = map(int, input().split())
x3, y3, x4, y4 = map(int, input().split())
ccw_a_1 = (x1 * y3 + x3 *y4+ x4*y1)-(x3*y1+x4*y3+x1*y4)
ccw_a_2 = (x2*y3+x3*y4+x4*y2) - (x3*y2+x4*y3+x2*y4)
ccw_a = ccw_a_1 * ccw_a_2
ccw_b_1 = (x3 * y1 + x1 *y2+ x2*y3)-(x1*y3+x2*y1+x3*y2)
ccw_b_2 = (x4 * y1 + x1 *y2+ x2*y4)-(x1*y4+x2*y1+x4*y2)
ccw_b = ccw_b_1 * ccw_b_2
if(ccw_a==0 and ccw_b==0):
if min(x1, x2) <= max(x3, x4) and min(x3, x4) <= max(x1, x2) and min(y1, y2)<= max(y3, y4) and min(y3,y4) <= max(y1, y2):
print(1)
else:
print(0)
elif(ccw_a<=0 and ccw_b<=0):
print(1)
else:
print(0)