-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yjhss
committed
May 3, 2023
1 parent
49d4e55
commit 28d4d86
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import sys | ||
|
||
n = int(sys.stdin.readline()) #n 입력 | ||
|
||
arr = [list(map(int,input().split())) for i in range(n)] #2차원 평면 위의 점 n개 입력 [[3,4],[1,1]] | ||
|
||
#병합정렬_merge | ||
def merge(left, right): | ||
i, j = 0, 0 | ||
sorted_list = [] | ||
while(i < len(left)) and (j < len(right)): | ||
if left[i] < right[j]: | ||
sorted_list.append(left[i]) | ||
i += 1 | ||
else: | ||
sorted_list.append(right[j]) | ||
j += 1 | ||
if i == len(left): | ||
while j < len(right): | ||
sorted_list.append(right[j]) | ||
j += 1 | ||
elif j == len(right): | ||
while i < len(left): | ||
sorted_list.append(left[i]) | ||
i += 1 | ||
return sorted_list | ||
|
||
#병합정렬_merge sort | ||
def merge_sort(arr): | ||
if len(arr) <= 1: | ||
return arr | ||
#분할하고 분할된 리스트 각각 정렬 | ||
mid = len(arr) // 2 | ||
left = merge_sort(arr[:mid]) | ||
right = merge_sort(arr[mid:]) | ||
#병합 | ||
return merge(left,right) | ||
|
||
#정렬 | ||
arr = merge_sort(arr) | ||
#좌표 출력 | ||
for x, y in arr: | ||
print(x,y) | ||
|
||
|