-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsol.py
More file actions
51 lines (35 loc) · 1.02 KB
/
Copy pathsol.py
File metadata and controls
51 lines (35 loc) · 1.02 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
from random import random
from math import sqrt, atan2, degrees
class Point:
def __init__(self, uid, x, y):
self.id = uid
self.x = x + random() / 1e9
self.y = y + random() / 1e9
self.r = 0
self.theta = 0
def computePolar(self, center):
x = self.x - center.x
y = self.y - center.y
self.r = sqrt(x * x + y * y)
self.theta = degrees(atan2(y, x))
def solve():
data = list(map(int, input().split()))
n = data[0]
points = []
avg_x = 0
avg_y = 0
for i in range(1, 2 * n, 2):
x, y = data[i], data[i + 1]
points.append(Point(i // 2, x, y))
avg_x += points[-1].x
avg_y += points[-1].y
center = Point(-1, avg_x / n, avg_y / n)
for p in points:
p.computePolar(center)
points.sort(key=lambda p: -p.r)
points.sort(key=lambda p: p.theta)
print(" ".join([str(p.id) for p in points]))
if __name__ == "__main__":
cases = int(input())
for i in range(cases):
solve()