ps | |
---|---|
링크 | acmicpc.net/… |
출처 | BOJ |
문제 번호 | 4181 |
문제명 | Convex Hull |
레벨 | 플래티넘 5 |
분류 |
기하학 |
시간복잡도 | O(t*nlogn) |
인풋사이즈 | n<=100,000 |
사용한 언어 | Python 3.11 |
제출기록 | 52768KB / 296ms |
최고기록 | 296ms |
해결날짜 | 2023/04/26 |
"""Solution code for "BOJ 4181. Convex Hull".
- Problem link: https://www.acmicpc.net/problem/4181
- Solution link: http://www.teferi.net/ps/problems/boj/4181
Tags: [geometry]
"""
import bisect
import math
import sys
from teflib import geometry
def main():
n = int(sys.stdin.readline())
points = []
for _ in range(n):
x, y, c = sys.stdin.readline().split()
if c == 'Y':
points.append([int(x), int(y)])
pole = min(points)
get_angle = geometry.polar_angle_key(pole)
points.sort(key=get_angle)
first_angle = get_angle(points[1])
pos = bisect.bisect_right(points, first_angle, key=get_angle)
points[1:pos] = sorted(points[1:pos], key=lambda p: math.dist(p, pole))
last_angle = get_angle(points[-1])
pos = bisect.bisect_left(points, last_angle, key=get_angle)
points[pos:] = sorted(points[pos:], key=lambda p: -math.dist(p, pole))
print(len(points))
for p in points:
print(*p)
if __name__ == '__main__':
main()