Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def distance(x):
- return (x[0] ** 2 + x[1] ** 2) ** 0.5
- def merge(A, B):
- c = []
- i = 0
- j = 0
- while i < len(A) and j < len(B):
- if distance(B[j]) > distance(A[i]):
- c.append(A[i])
- i += 1
- else:
- c.append(B[j])
- j += 1
- c += A[i:] + B[j:]
- return c
- def mergesort(A):
- if len(A) < 2:
- return A
- m = len(A) // 2
- L = mergesort(A[:m])
- R = mergesort(A[m:])
- Z = merge(L, R)
- return Z
- n = int(input())
- a = [[]] * n
- for i in range(n):
- a[i] = list(map(int, input().split()))
- ans = mergesort(a)
- for x in ans:
- print(*x)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement