# print("hello python world") # 블록 껍질 '''https://w...content-available-to-author-only...c.net/problem/1708''' # Method : 그라함 스캔 알고리즘 import sys # 각도 구하는 알고리즘 # 실제 각도가 아닌 dx가 0이 되는 것을 방지하기 위함 def theta(a, b): xa, ya = points[a] xb, yb = points[b] dx, dy = xb - xa, yb - ya ax, ay = abs(dx), abs(dy) if ax + ay == 0: return 0 else: t = dy / (ax + ay) if dx < 0: return 2 - t elif dy < 0: return 4 + t else: return t # CCW 알고리즘 : 벡터의 외적에서 방향을 확인 def ccw(i, j, k): (vx1, vy1), (vx2, vy2) = vector(i, j), vector(j, k) product_value = vx1 * vy2 - vy1 * vx2 return True if product_value > 0 else False # vector 생성 함수 def vector(idx1, idx2): # 1 -> 2로 가는 벡터 생성 (x1, y1), (x2, y2) = points[idx1], points[idx2] return x2 - x1, y2 - y1 if __name__ == "__main__": try: N = int(sys.stdin.readline()) points = [tuple(map(int, sys.stdin.readline().split(" "))) for _ in range(N)] standard_point = 0 for idx, (x, y) in enumerate(points[1:], start=1): if points[standard_point][1] > y: standard_point = idx elif points[standard_point][1] == y and points[standard_point][0] < x: standard_point = idx theta_list = [[i, 10] for i in range(N)] for idx in range(N): theta_list[idx][1] = theta(standard_point, idx) theta_list.sort(key=lambda x: x[1]) print("sorted : ") for p, _ in theta_list: print(points[p]) stack = [standard_point] for p, _ in theta_list: if p == standard_point: continue while len(stack) > 1 and not ccw(stack[-2], stack[-1], p): stack.pop() stack.append(p) while len(stack) > 1 and not ccw(stack[-2], stack[-1], standard_point): stack.pop() print(len(stack)) print("convex hull : ") for idx in stack: print(*points[idx]) except ValueError or IndexError as e: print(e)
105 13 100 0 27 0 7 -13 13 -80 80 -85 85 -3 3 0 67 -58 58 -16 16 71 71 -67 67 89 89 0 0 0 84 64 64 0 24 0 55 43 43 68 68 -21 21 29 29 0 53 8 8 -19 19 97 97 -100 100 100 100 76 76 -23 23 63 63 -40 40 -98 98 -6 6 -92 92 -43 43 -31 31 0 41 61 61 99 99 0 15 25 25 0 38 0 89 62 62 66 66 -51 51 67 67 0 18 42 42 52 52 0 10 -57 57 0 58 56 56 -29 29 5 5 81 81 95 95 -36 36 70 70 88 88 -87 87 0 11 0 14 60 60 3 3 -46 46 0 94 0 44 77 77 2 2 16 16 0 92 83 83 -28 28 87 87 -10 10 30 30 -56 56 -86 86 -73 73 -20 20 0 63 21 21 92 92 10 10 98 98 0 37 -27 27 74 74 7 7 0 101 65 65 48 48 0 90 0 59 -69 69 0 25 -17 17 -63 63 14 14 0 57 -78 78 0 88
sorted : (0, 0) (71, 71) (89, 89) (64, 64) (43, 43) (68, 68) (29, 29) (8, 8) (97, 97) (100, 100) (76, 76) (63, 63) (61, 61) (99, 99) (25, 25) (62, 62) (66, 66) (67, 67) (42, 42) (52, 52) (56, 56) (5, 5) (81, 81) (95, 95) (70, 70) (88, 88) (60, 60) (3, 3) (77, 77) (2, 2) (16, 16) (83, 83) (87, 87) (30, 30) (21, 21) (92, 92) (10, 10) (98, 98) (74, 74) (7, 7) (65, 65) (48, 48) (14, 14) (13, 100) (0, 27) (0, 7) (0, 67) (0, 84) (0, 24) (0, 55) (0, 53) (0, 41) (0, 15) (0, 38) (0, 89) (0, 18) (0, 10) (0, 58) (0, 11) (0, 14) (0, 94) (0, 44) (0, 92) (0, 63) (0, 37) (0, 101) (0, 90) (0, 59) (0, 25) (0, 57) (0, 88) (-13, 13) (-80, 80) (-85, 85) (-3, 3) (-58, 58) (-16, 16) (-67, 67) (-21, 21) (-19, 19) (-100, 100) (-23, 23) (-40, 40) (-98, 98) (-6, 6) (-92, 92) (-43, 43) (-31, 31) (-51, 51) (-57, 57) (-29, 29) (-36, 36) (-87, 87) (-46, 46) (-28, 28) (-10, 10) (-56, 56) (-86, 86) (-73, 73) (-20, 20) (-27, 27) (-69, 69) (-17, 17) (-63, 63) (-78, 78) 5 convex hull : 0 0 14 14 13 100 0 101 -100 100