-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.py
More file actions
executable file
·80 lines (56 loc) · 1.95 KB
/
Copy pathsol.py
File metadata and controls
executable file
·80 lines (56 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import sys
import math
def rotate_point(x, y, angle):
s = math.sin(math.radians(angle))
c = math.cos(math.radians(angle))
return (x * c - y * s, x * s + y * c)
def calculateBoundingBoxArea(point_a, point_b):
print(point_a, point_b)
min_x = point_a[0]
max_x = point_b[0]
min_y = point_a[1]
max_y = point_b[1]
print("-------- RESULT: ", abs(max_y - min_y) * abs(max_x - min_x))
return abs(max_y - min_y) * abs(max_x - min_x)
def calculateAreaForSplit(points, p_i):
return calculateBoundingBoxArea(points[0], points[p_i]) + calculateBoundingBoxArea(
points[p_i + 1], points[-1]
)
def calculateOptimalSplitArea(points, alt_index):
min_area = sys.maxsize
alts = sorted([p[alt_index] for p in points])
heap_l = heapify(alts)
heap_r = []
for i in range(len(points) - 1):
first.remove(points[i][alt_index])
second.append(points[i])
second = sorted(second)
first_area =
min_area = min(min_area, calculateAreaForSplit(points, i))
print("min_area: ", min_area)
return min_area
def solve():
point_count = int(input())
points = []
for i in range(point_count):
x, y = [int(_) for _ in input().split(" ")]
rx, ry = rotate_point(x, y, -0.001)
points.append((x, y, rx, ry))
points = sorted(points, key=lambda p: p[2])
bbox_area = calculateBoundingBoxArea(points[0], points[-1])
print("bbox_area: ", bbox_area)
print("=" * 20)
horizontal_split_area = calculateOptimalSplitArea(points)
print("hsplit: ", horizontal_split_area)
print("=" * 20)
points = sorted(points, key=lambda p: p[3])
vertical_split_area = calculateOptimalSplitArea(points)
print("vsplit: ", vertical_split_area)
print("=" * 20)
print(min(bbox_area, horizontal_split_area, vertical_split_area))
if __name__ == "__main__":
T = int(input())
while T:
print("=" * 80)
solve()
T -= 1