From f9570f2f0cfb45129df0c1d203082dd65e6de71d Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Wed, 26 Apr 2023 21:06:50 +0900 Subject: [PATCH 1/5] =?UTF-8?q?#10=20:=2011279=5F=EC=B5=9C=EB=8C=80=20?= =?UTF-8?q?=ED=9E=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...279_\354\265\234\353\214\200 \355\236\231.py" | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\234\240\354\247\204/11279_\354\265\234\353\214\200 \355\236\231.py" diff --git "a/\354\235\264\355\213\260\354\234\240\354\247\204/11279_\354\265\234\353\214\200 \355\236\231.py" "b/\354\235\264\355\213\260\354\234\240\354\247\204/11279_\354\265\234\353\214\200 \355\236\231.py" new file mode 100644 index 0000000..a2239aa --- /dev/null +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/11279_\354\265\234\353\214\200 \355\236\231.py" @@ -0,0 +1,16 @@ +import sys +import heapq + +n = int(sys.stdin.readline()) +heap = [] + +# -1을 곱해 최소 힙으로 최대 힙 구현 +for i in range (n): + x = int(sys.stdin.readline()) + if x == 0: # x가 0일 때 + if heap: # 배열에서 가장 큰 값 출력하고 그 값을 배열에서 삭제 + print((-1)*heapq.heappop(heap)) + else: # 배열이 비어있을 경우 0 출력 + print(0) + elif x > 0: # x가 자연수일 때 + heapq.heappush(heap,(-1)*x) # 배열에 x라는 값 추가 From a1e7e02139e15a49555f30834643784bd1215065 Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Wed, 26 Apr 2023 21:59:22 +0900 Subject: [PATCH 2/5] =?UTF-8?q?#10=20:=201966=5F=ED=94=84=EB=A6=B0?= =?UTF-8?q?=ED=84=B0=20=ED=81=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\246\260\355\204\260 \355\201\220.py" | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" diff --git "a/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" "b/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" new file mode 100644 index 0000000..5a540ed --- /dev/null +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" @@ -0,0 +1,24 @@ +import sys + +t = int(sys.stdin.readline()) # 테스트 케이스 개수 t + +for i in range (t): + n, m = map(int, input().split()) + queue = list(map(int, input().split())) # 리스트 queue + cnt = 0 # 문서의 출력 순서를 세기 위한 변수 cnt + + while queue: + if queue[0] == max(queue): # 맨 앞 문서의 중요도가 가장 클 때 + del queue[0] # 맨 앞 문서 삭제 + m -= 1 # 문서 위치 왼쪽으로 한 번 이동하므로 m 값 1 감소 + cnt +=1 # 문서 하나 출력 되었으므로 cnt 값 1 증가 + else: # 맨 앞 문서의 중요도가 가장 크지 않을 때 + queue.append(queue[0]) # 이 문서를 맨 뒤에 추가 + del queue[0] # 맨 앞에서 삭제 + + if m == 0: # m이 0일 경우 + m = len(queue)-1 # m 맨 뒤 가리킴 + else: # m이 0이 아닐 경우 + m -= 1 # m 값 1 감소 + + print(cnt) # cnt 값 출력 \ No newline at end of file From 49d4e5511baf7a71769fd6ab601e5cf913708a01 Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Wed, 3 May 2023 01:15:57 +0900 Subject: [PATCH 3/5] =?UTF-8?q?#10=20:=201966=5F=ED=94=84=EB=A6=B0?= =?UTF-8?q?=ED=84=B0=20=ED=81=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\353\246\260\355\204\260 \355\201\220.py" | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git "a/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" "b/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" index 5a540ed..cffb0e8 100644 --- "a/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/1966_\355\224\204\353\246\260\355\204\260 \355\201\220.py" @@ -1,24 +1,19 @@ import sys +from collections import deque -t = int(sys.stdin.readline()) # 테스트 케이스 개수 t - -for i in range (t): - n, m = map(int, input().split()) - queue = list(map(int, input().split())) # 리스트 queue - cnt = 0 # 문서의 출력 순서를 세기 위한 변수 cnt +t = int(sys.stdin.readline()) #테스트 케이스 수 t +for i in range(t): + n, m = map(int,input().split()) + queue = deque(list(map(int,input().split()))) #문서 중요도 queue + index_queue = deque(list(range(n))) #인덱스 idx_queue + cnt = 0 #인쇄 순서 cnt while queue: - if queue[0] == max(queue): # 맨 앞 문서의 중요도가 가장 클 때 - del queue[0] # 맨 앞 문서 삭제 - m -= 1 # 문서 위치 왼쪽으로 한 번 이동하므로 m 값 1 감소 - cnt +=1 # 문서 하나 출력 되었으므로 cnt 값 1 증가 - else: # 맨 앞 문서의 중요도가 가장 크지 않을 때 - queue.append(queue[0]) # 이 문서를 맨 뒤에 추가 - del queue[0] # 맨 앞에서 삭제 - - if m == 0: # m이 0일 경우 - m = len(queue)-1 # m 맨 뒤 가리킴 - else: # m이 0이 아닐 경우 - m -= 1 # m 값 1 감소 - - print(cnt) # cnt 값 출력 \ No newline at end of file + if queue[0] == max(queue): #queue의 첫번째 원소가 최댓값인 경우(가장 앞에 있는 문서의 중요도가 가장 클 경우) pop + cnt += 1 #pop할 때마다 cnt 1씩 증가 + queue.popleft() + if index_queue.popleft() == m: #pop한 문서의 인덱스가 m과 같다면 cnt 출력 + print(cnt) + else: + queue.append(queue.popleft()) #queue의 첫번째 원소가 최댓값 아닌 경우 맨 뒤로 재배치 + index_queue.append(index_queue.popleft()) \ No newline at end of file From 28d4d8639f9eddce8c0254f47c9e2f073acd9ffd Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Thu, 4 May 2023 07:28:30 +0900 Subject: [PATCH 4/5] =?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" | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\234\240\354\247\204/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\234\240\354\247\204/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\234\240\354\247\204/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..ea57f3b --- /dev/null +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/11650_\354\242\214\355\221\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" @@ -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) + + From 03e25210341ce00116a2e0b83282042592286a81 Mon Sep 17 00:00:00 2001 From: yjhss <20211420.sungshin.ac.kr> Date: Thu, 4 May 2023 08:55:42 +0900 Subject: [PATCH 5/5] =?UTF-8?q?#14=20:=201431=5F=EC=8B=9C=EB=A6=AC?= =?UTF-8?q?=EC=96=BC=20=EB=B2=88=ED=98=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\226\274 \353\262\210\355\230\270.py" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "\354\235\264\355\213\260\354\234\240\354\247\204/1431_\354\213\234\353\246\254\354\226\274 \353\262\210\355\230\270.py" diff --git "a/\354\235\264\355\213\260\354\234\240\354\247\204/1431_\354\213\234\353\246\254\354\226\274 \353\262\210\355\230\270.py" "b/\354\235\264\355\213\260\354\234\240\354\247\204/1431_\354\213\234\353\246\254\354\226\274 \353\262\210\355\230\270.py" new file mode 100644 index 0000000..6f3a063 --- /dev/null +++ "b/\354\235\264\355\213\260\354\234\240\354\247\204/1431_\354\213\234\353\246\254\354\226\274 \353\262\210\355\230\270.py" @@ -0,0 +1,22 @@ +import sys + +n = int(sys.stdin.readline()) #기타 개수 n 입력 +s = [input() for i in range(n)] #시리얼 번호 n개 입력 + +#정렬 2_자릿수 합 +def sum(x): + r = 0 + for i in x: + if i.isdigit(): #isdigit(): 문자열이 숫자인지 판별 + r += int (i) + return r + +#정렬_ 1.길이 2.자릿수 합 3.사전순 +s.sort(key = lambda x: (len(x), sum(x), x)) + +#정렬된 리스트 s의 모든 요소 출력 +for i in s: + print(i) + + +