BOJ - 1708 - 볼록 껍질
Updated:
import sys
def getDegree(p1, p2):
return p2[0] - p1[0], p2[1] - p1[1]
def ccw(p1, p2, p3):
v, u = getDegree(p1, p2), getDegree(p2, p3)
if v[0] * u[1] > v[1] * u[0]: return True
else: return False
def convex_hull(position):
convex = []
for p3 in position:
while len(convex) >= 2:
p1, p2 = convex[-2], convex[-1]
if ccw(p1, p2, p3):
break
convex.pop()
convex.append(p3)
return len(convex)
def solution():
N = int(input())
ret = 0
position = []
for _ in range(N):
position.append(list(map(int, sys.stdin.readline().split())))
position = sorted(position, key=lambda x:(x[0], x[1]))
ret += convex_hull(position)
position.reverse()
ret += convex_hull(position)
print(ret - 2)
solution()
https://www.acmicpc.net/problem/1708
Leave a comment