Cows

난이도

Platinum 5

인증

문제

Your friend to the south is interested in building fences and turning plowshares into swords. In order to help with his overseas adventure, they are forced to save money on buying fence posts by using trees as fence posts wherever possible. Given the locations of some trees, you are to help farmers try to create the largest pasture that is possible. Not all the trees will need to be used.

However, because you will oversee the construction of the pasture yourself, all the farmers want to know is how many cows they can put in the pasture. It is well known that a cow needs at least 50 square metres of pasture to survive.

입력

The first line of input contains a single integer, n (1 ≤ n ≤ 10000), containing the number of trees that grow on the available land. The next n lines contain the integer coordinates of each tree given as two integers x and y separated by one space (where −1000 ≤ x, y ≤ 1000). The integer coordinates correlate exactly to distance in metres (e.g., the distance between coordinate (10, 11) and (11, 11) is one metre).

출력

You are to output a single integer value, the number of cows that can survive on the largest field you can construct using the available trees.

예제 입력

4
0 0
0 101
75 0
75 101

예제 출력

151

해설 및 후기

이 문제부터는 컨벡스 헐 이론을 알고 있다고 가정하기 시작했다. 하지만 풀이 자체는 간단한데, 컨벡스 헐을 이루고 있는 점들을 어떤 방향으로 순회하며 헤론의 공식을 이용해 다각형의 넓이를 구하면 된다. 내가 구한 방식의 컨벡스 헐 점들은 각각 윗 볼록껍질/아래 볼록 껍질 나누어 저장되어 있기 때문에 나누어서 구하고, 이를 50으로 정수 나눔한 값을 출력한다.

제출 코드

import sys
import math
n = int(sys.stdin.readline().rstrip())

def ccw(a,b,c):
    res = (b[0]-a[0])*(c[1]-a[1]) - (c[0]-a[0])*(b[1]-a[1])
    if(res < 0):
        return -1
    elif(res > 0):
        return 1
    else:
        return 0

def heron(a,b,c):
    aa = ((a[0]-b[0])**2 + (a[1]-b[1])**2)**0.5
    bb = ((b[0]-c[0])**2 + (b[1]-c[1])**2)**0.5
    cc = ((c[0]-a[0])**2 + (c[1]-a[1])**2)**0.5
    s = (aa+bb+cc)/2
    res = (s*(s-aa)*(s-bb)*(s-cc))**0.5
    return res

def getSize(l):
    base = l[0]
    res = 0
    for i in range(len(l)-2):
        res += heron(base,l[i+1],l[i+2])
    return res

lsts = []
for i in range(n):
    x,y = map(int,sys.stdin.readline().rstrip().split())
    lsts.append([x,y])

lsts = sorted(lsts, key=lambda x:(x[0], x[1]))
cnt = 0
stk = []
for point in lsts:
    while(len(stk)>1 and ccw(stk[-2], stk[-1], point)<=0):
          stk.pop()
    stk.append(point)
cnt += len(stk)
tmpStk = stk[:]
stk = []
for point in lsts:
    while(len(stk)>1 and ccw(stk[-2], stk[-1], point)>=0):
          stk.pop()
    stk.append(point)
cnt += len(stk)
s = getSize(stk)
s += getSize(tmpStk)
print(int(s//50))