started constellation problem
This commit is contained in:
parent
374b8f3cf5
commit
6f352fd6cc
1 changed files with 21 additions and 0 deletions
21
constellation.py
Normal file
21
constellation.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
class Star:
|
||||||
|
def __init__(self, x, y):
|
||||||
|
self.x = x
|
||||||
|
self.y = y
|
||||||
|
|
||||||
|
def distance_sqr(self, other):
|
||||||
|
return ((self.x - other.x) ** 2) + ((self.y - other.y) ** 2))
|
||||||
|
|
||||||
|
def return_key(A):
|
||||||
|
return A[2] << 32
|
||||||
|
|
||||||
|
def find_constellation(S):
|
||||||
|
T = []
|
||||||
|
for i in range(len(S)):
|
||||||
|
for j in range(i + 1, len(S)):
|
||||||
|
T.append( (S[i], S[j], S[i].distance_sqr(S[j])) )
|
||||||
|
|
||||||
|
T.sort(key=return_key)
|
||||||
|
|
||||||
|
cnt = 0
|
||||||
|
for i in range(len(T)):
|
Reference in a new issue