[BOJ] 11758번 CCW - Python

"기하"

Posted by Yongmin on September 28, 2021

문제

CCW

풀이

벡터 외적으로 0보다 크면 반시계, 작으면 시계, 0이면 평형인 것을 이용하여 정답을 도출해냈다

소스 코드

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import sys
from math import *

def ccw(x1, y1, x2, y2, x3, y3):
    return (x1*y2 + x2*y3 + x3*y1) - (x1*y3 + x3*y2 + x2*y1)

pointlist = []

for _ in range(3):
    a, b = map(int, input().split())
    pointlist.append([a, b])

result = ccw(pointlist[0][0], pointlist[0][1], pointlist[1][0], pointlist[1][1], pointlist[2][0], pointlist[2][1])
if(result > 0):
    print(1)
elif(result < 0):
    print(-1)
else:
    print(0)


# # #