From f69831b353eccb46d5d231a33e24c9a1005d8a79 Mon Sep 17 00:00:00 2001 From: Jiyun Kim Date: Wed, 3 May 2023 17:28:19 +0900 Subject: [PATCH] =?UTF-8?q?#14=20:=2011650=5F=EC=A2=8C=ED=91=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=ED=95=98=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...25\353\240\254\355\225\230\352\270\260.py" | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\247\200\354\234\244/11650_\354\242\214\355\221\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" diff --git "a/\354\235\264\355\213\260\354\247\200\354\234\244/11650_\354\242\214\355\221\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" "b/\354\235\264\355\213\260\354\247\200\354\234\244/11650_\354\242\214\355\221\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..92f9228 --- /dev/null +++ "b/\354\235\264\355\213\260\354\247\200\354\234\244/11650_\354\242\214\355\221\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" @@ -0,0 +1,42 @@ +import sys +input = sys.stdin.readline + +n = int(input()) # 입력할 좌표 수 : 2차원 배열의 크기 + +def merge_sort(arr): + if len(arr) < 2: + return arr + mid = len(arr) // 2 + left = merge_sort(arr[:mid]) + right = merge_sort(arr[mid:]) + merged_arr = [] + l = r = 0 + + while l < len(left) and r < len(right): + # x 좌표가 같을 경우 : y좌표를 비교해서 작은 값 리스트에 넣기 + #[][0] : x좌표, [][1] : y좌표인 2차원 배열 + if left[l][0] == right[r][0]: + if left[l][1] < right[r][1]: + merged_arr.append(left[l]) + l += 1 + else: + merged_arr.append(right[r]) + r += 1 + elif left[l][0] < right[r][0]: + merged_arr.append(left[l]) + l += 1 + else: + merged_arr.append(right[r]) + r += 1 + + merged_arr += left[l:] + merged_arr += right[r:] + + return merged_arr + +# 입력받은 문자열 n개의 행을 int형 2차원 리스트로 변환-> a에 할당 +a = [list(map(int,input().split())) for i in range(n)] +a = merge_sort(a) + +for i in a: + print(i[0],i[1]) \ No newline at end of file