From 66752ba136ff82ef9d13b6e2b16d43154a4b57f4 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Wed, 11 Sep 2024 22:34:06 +0900 Subject: [PATCH 01/16] =?UTF-8?q?2024-09-11=20=EC=B9=B4=EB=93=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC=ED=95=98=EA=B8=B0.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...225\353\240\254\355\225\230\352\270\260.py" | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 "LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" diff --git "a/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" "b/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" new file mode 100644 index 0000000..ba42acf --- /dev/null +++ "b/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \354\240\225\353\240\254\355\225\230\352\270\260.py" @@ -0,0 +1,18 @@ +import sys +import heapq +input = sys.stdin.readline + +cards = list(int(input()) for _ in range(int(input().strip()))) # 데이터 입력받음 +heapq.heapify(cards) # 리스트를 힙구조로 바꿔주는 함수 + +result = 0 +while len(cards) > 1 : + f = heapq.heappop(cards) # 첫번째 뭉탱이 + s = heapq.heappop(cards) # 두번째 뭉탱이 + + result += f+s + + # 바꿔치기 횟수가 최소가 되게끔 + heapq.heappush(cards, f+s) + +print(result) \ No newline at end of file From 1c975acbfcc2fc1855eaf6974751e8a899d70202 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sun, 22 Sep 2024 15:34:08 +0900 Subject: [PATCH 02/16] =?UTF-8?q?2024-09-18=20N=EB=B2=88=EC=A7=B8=20?= =?UTF-8?q?=ED=81=B0=EC=88=98.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LJEDD2/2024-2/README.md | 3 ++- ...10\354\247\270 \355\201\260 \354\210\230.py" | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 "LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index f93efc8..f53d727 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -10,4 +10,5 @@ | 6차시 | 2024.08.03 | 완전탐색 | 피로도 | [#6](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/141) | | 7차시 | 2024.09.01 | 위상정렬 | 줄 세우기 | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) | | 8차시 | 2024.09.04 | 위상정렬 | 문제집 | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) | -| 9차시 | 2024.09.07 | 스택 | 원숭이 매달기 | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) | \ No newline at end of file +| 9차시 | 2024.09.07 | 스택 | 원숭이 매달기 | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) | +| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | \ No newline at end of file diff --git "a/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" "b/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" new file mode 100644 index 0000000..57ae8b3 --- /dev/null +++ "b/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/N\353\262\210\354\247\270 \355\201\260 \354\210\230.py" @@ -0,0 +1,17 @@ +import sys, heapq +input = sys.stdin.readline + +n = int(input()) +heap = [] + +for _ in range(n): + for number in map(int, input().split()): + + if len(heap) < n: # 비교 대상이 모자랄 경우 + heapq.heappush(heap, number) #그대로 추가 + + else: + if number > heap[0]: # 제일 작은것보다 크면 + heapq.heapreplace(heap, number) #작은거 빼고 큰거 넣어줌 + +print(heap[0]) # 맨앞에 있는게 N번째로 큰놈 \ No newline at end of file From 3f50541a25777e846b1562990fd672867cb8ea10 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 26 Sep 2024 00:11:31 +0900 Subject: [PATCH 03/16] 2024-09-18 --- LJEDD2/2024-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index f53d727..dcf7687 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -11,4 +11,5 @@ | 7차시 | 2024.09.01 | 위상정렬 | 줄 세우기 | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) | | 8차시 | 2024.09.04 | 위상정렬 | 문제집 | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) | | 9차시 | 2024.09.07 | 스택 | 원숭이 매달기 | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) | -| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | \ No newline at end of file +| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | +| 11차시 | 2024.09.18 | 우선순위 큐 | N번째 큰 수 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) | \ No newline at end of file From 8db95cc680cb2eb6f1e77e0695e7f0a29cf6d209 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 26 Sep 2024 00:14:31 +0900 Subject: [PATCH 04/16] =?UTF-8?q?2024-09-21=20=EC=B9=B4=EB=93=9C=20?= =?UTF-8?q?=ED=95=A9=EC=B2=B4=20=EB=86=80=EC=9D=B4.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...251\354\262\264 \353\206\200\354\235\264.py" | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 "LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.py" diff --git "a/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.py" "b/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.py" new file mode 100644 index 0000000..d0a62f1 --- /dev/null +++ "b/LJEDD2/2024-2/\354\232\260\354\204\240\354\210\234\354\234\204\355\201\220/\354\271\264\353\223\234 \355\225\251\354\262\264 \353\206\200\354\235\264.py" @@ -0,0 +1,17 @@ +import heapq +n, m = map(int,input().split()) + +#힙 구조로 변환 +numbers = list(map(int,input().split())) +heapq.heapify(numbers) + +for _ in range(m): + + x = heapq.heappop(numbers) + y = heapq.heappop(numbers) + + # x와 y 둘 다 값 교체 + heapq.heappush(numbers, x+y) + heapq.heappush(numbers, x+y) + +print(sum(numbers)) From 79029cff270def7ea84fcb82a81725d34aeaaac9 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 26 Sep 2024 00:15:30 +0900 Subject: [PATCH 05/16] Revert "2024-09-18" This reverts commit 3f50541a25777e846b1562990fd672867cb8ea10. --- LJEDD2/2024-2/README.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index dcf7687..f53d727 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -11,5 +11,4 @@ | 7차시 | 2024.09.01 | 위상정렬 | 줄 세우기 | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) | | 8차시 | 2024.09.04 | 위상정렬 | 문제집 | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) | | 9차시 | 2024.09.07 | 스택 | 원숭이 매달기 | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) | -| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | -| 11차시 | 2024.09.18 | 우선순위 큐 | N번째 큰 수 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) | \ No newline at end of file +| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | \ No newline at end of file From e76ce008b42db632acff6f72b0d228dc1c9d6260 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 26 Sep 2024 00:18:59 +0900 Subject: [PATCH 06/16] 2024-09-26 --- LJEDD2/2024-2/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index f53d727..b7d1168 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -11,4 +11,6 @@ | 7차시 | 2024.09.01 | 위상정렬 | 줄 세우기 | [#7](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/152) | | 8차시 | 2024.09.04 | 위상정렬 | 문제집 | [#8](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/154) | | 9차시 | 2024.09.07 | 스택 | 원숭이 매달기 | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) | -| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | \ No newline at end of file +| 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | +| 11차시 | 2024.09.18 | 우선순위 큐 | N번째 큰 수 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) | +| 12차시 | 2024.09.21 | 우선순위 큐 | 카드 합체 놀이 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/164) | From a3c81187dc97729c25e259015aceb3ad4a993092 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 26 Sep 2024 00:19:59 +0900 Subject: [PATCH 07/16] 2024-09-21 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 날짜 기입 수정 --- LJEDD2/2024-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index b7d1168..b43956b 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -13,4 +13,4 @@ | 9차시 | 2024.09.07 | 스택 | 원숭이 매달기 | [#9](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/156) | | 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | | 11차시 | 2024.09.18 | 우선순위 큐 | N번째 큰 수 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) | -| 12차시 | 2024.09.21 | 우선순위 큐 | 카드 합체 놀이 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/164) | +| 12차시 | 2024.09.21 | 우선순위 큐 | 카드 합체 놀이 | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/164) | From 55221545d3de7572855ea88207bbaa9315383568 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 28 Sep 2024 00:42:00 +0900 Subject: [PATCH 08/16] =?UTF-8?q?2024-09-25=20=EC=B9=9C=EA=B5=AC.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\354\271\234\352\265\254.py" | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 "LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" diff --git "a/LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" "b/LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" new file mode 100644 index 0000000..ccc6017 --- /dev/null +++ "b/LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" @@ -0,0 +1,21 @@ +import sys +input = sys.stdin.readline + +n = int(input()) +graph = [list(input().strip()) for _ in range(n)] +visited = [[0] * n for _ in range(n)] + +for k in range(n): + for i in range(n): + for j in range(n): + if i == j: + continue + + # 2-친구인 경우 + if graph[i][j] == 'Y' or (graph[i][k] == 'Y' and graph[k][j] == 'Y'): + visited [i][j] = 1 + +res = 0 +for row in visited: + res = max(res,sum(row)) +print(res) \ No newline at end of file From 4109c043fe2e3f8b5cf8344753dfc3e7ab48c0aa Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 28 Sep 2024 00:43:54 +0900 Subject: [PATCH 09/16] 2024-09-25 --- .../\354\271\234\352\265\254.py" | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename "LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" => "LJEDD2/2024-2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" (100%) diff --git "a/LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" "b/LJEDD2/2024-2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" similarity index 100% rename from "LJEDD2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" rename to "LJEDD2/2024-2/\355\224\214\353\241\234\354\235\264\353\223\234 \354\233\214\354\205\234/\354\271\234\352\265\254.py" From 7cd3ffe4b4a9bee70e45ab3238d993034ba21843 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 28 Sep 2024 22:43:44 +0900 Subject: [PATCH 10/16] =?UTF-8?q?2024-09-28=20=EC=B9=B4=EB=93=9C1.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\355\201\220/\354\271\264\353\223\2341.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "LJEDD2/2024-2/\355\201\220/\354\271\264\353\223\2341.py" diff --git "a/LJEDD2/2024-2/\355\201\220/\354\271\264\353\223\2341.py" "b/LJEDD2/2024-2/\355\201\220/\354\271\264\353\223\2341.py" new file mode 100644 index 0000000..0086850 --- /dev/null +++ "b/LJEDD2/2024-2/\355\201\220/\354\271\264\353\223\2341.py" @@ -0,0 +1,14 @@ +import sys +from collections import deque +input = sys.stdin.readline + +n = int(input().strip()) +queue = deque([i for i in range(1, n+1)]) +result = [] + +while len(queue) > 1: + result.append(queue.popleft()) + queue.append(queue.popleft()) +else: + result.append(queue.popleft()) +print(" ".join(map(str, result))) \ No newline at end of file From 1485ee4dd7a85a29fbcbd76d068dc1d7cbe6a86f Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Wed, 9 Oct 2024 00:52:15 +0900 Subject: [PATCH 11/16] =?UTF-8?q?2024-10-02=20=EC=84=B8=20=EA=B0=9C?= =?UTF-8?q?=EC=9D=98=20=EC=86=8C=EC=88=98=20=EB=AC=B8=EC=A0=9C.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...4\354\210\230 \353\254\270\354\240\234.py" | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 "LJEDD2/2024-2/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/\354\204\270 \352\260\234\354\235\230 \354\206\214\354\210\230 \353\254\270\354\240\234.py" diff --git "a/LJEDD2/2024-2/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/\354\204\270 \352\260\234\354\235\230 \354\206\214\354\210\230 \353\254\270\354\240\234.py" "b/LJEDD2/2024-2/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/\354\204\270 \352\260\234\354\235\230 \354\206\214\354\210\230 \353\254\270\354\240\234.py" new file mode 100644 index 0000000..f84d5a6 --- /dev/null +++ "b/LJEDD2/2024-2/\353\270\214\353\243\250\355\212\270\355\217\254\354\212\244/\354\204\270 \352\260\234\354\235\230 \354\206\214\354\210\230 \353\254\270\354\240\234.py" @@ -0,0 +1,30 @@ +import sys +input = sys.stdin.readline + +# 하나의 소수를 여러 번 더할 수 있다. -> 브루트포스 가능 +# 5보다 큰 임의의 홀수로 세 소수의 합이 되는지 +def search(n): + for i in arr: + for j in arr: + for k in arr: + if i+j+k == n: + return i, j, k + + else: # 안되면 0 + return 0 + +# 에라토스테네스의 체 - 소수 판별 +prime = [True] * 1001 + +for i in range(2,101): + if prime[i]: + for j in range(i*2, 1001, i): + prime[j] = False + +# 소수 찾기 +arr = [i for i in range(2, 1001) if prime[i] == True] + +t = int(input()) +for _ in range(t): + n = int(input()) + print(*search(n)) \ No newline at end of file From 6f0214b2905f185decca64783b4e95863c18bc37 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Wed, 9 Oct 2024 00:54:09 +0900 Subject: [PATCH 12/16] 2024-10-02 --- LJEDD2/2024-2/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index b43956b..df7d878 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -14,3 +14,5 @@ | 10차시 | 2024.09.11 | 우선순위 큐 | 카드 정렬하기 | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/159) | | 11차시 | 2024.09.18 | 우선순위 큐 | N번째 큰 수 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) | | 12차시 | 2024.09.21 | 우선순위 큐 | 카드 합체 놀이 | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/164) | +| 13차시 | 2024.09.25 | 플로이드 워셜 | 친구 | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/167) | +| 14차시 | 2024.10.02 | 브루트포스 | 세 개의 소수 문제 | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/174) | \ No newline at end of file From f7b25a58214419404de483188dd9fa2b5c109586 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 17 Oct 2024 23:22:51 +0900 Subject: [PATCH 13/16] =?UTF-8?q?2024-10-05=20=EB=A7=88=EC=A7=80=EB=A7=89?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3\247\210\354\247\200\353\247\211 \353\254\270\354\240\234.py" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "LJEDD2/2024-2/\352\267\270\353\246\254\353\224\224/\353\247\210\354\247\200\353\247\211 \353\254\270\354\240\234.py" diff --git "a/LJEDD2/2024-2/\352\267\270\353\246\254\353\224\224/\353\247\210\354\247\200\353\247\211 \353\254\270\354\240\234.py" "b/LJEDD2/2024-2/\352\267\270\353\246\254\353\224\224/\353\247\210\354\247\200\353\247\211 \353\254\270\354\240\234.py" new file mode 100644 index 0000000..e69de29 From 4b1941e1bad5f92f106b6ac28c6f44ae541e68ea Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Thu, 17 Oct 2024 23:28:05 +0900 Subject: [PATCH 14/16] 2024-10-05 --- LJEDD2/2024-2/README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index df7d878..0659f23 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -15,4 +15,6 @@ | 11차시 | 2024.09.18 | 우선순위 큐 | N번째 큰 수 | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/161) | | 12차시 | 2024.09.21 | 우선순위 큐 | 카드 합체 놀이 | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/164) | | 13차시 | 2024.09.25 | 플로이드 워셜 | 친구 | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/167) | -| 14차시 | 2024.10.02 | 브루트포스 | 세 개의 소수 문제 | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/174) | \ No newline at end of file +| 14차시 | 2024.09.28 | 큐 | 카드1 | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/170) | +| 15차시 | 2024.10.02 | 브루트포스 | 세 개의 소수 문제 | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/174) | +| 16차시 | 2024.10.05 | 그리디 | 마지막 문제 | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/179) | \ No newline at end of file From 18c327538727fee06a2ad81eef2356381ff421b8 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 2 Nov 2024 21:39:28 +0900 Subject: [PATCH 15/16] 2024-11-02 DSLR.py --- .../DSLR.py" | 50 +++++++++++++++++++ ...54\355\226\211\352\262\275\353\241\234.py" | 0 2 files changed, 50 insertions(+) create mode 100644 "LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/DSLR.py" rename "LJEDD2/2024-2/\352\271\212\354\235\264/\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211(DFS/BFS)/\354\227\254\355\226\211\352\262\275\353\241\234.py" => "LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/\354\227\254\355\226\211\352\262\275\353\241\234.py" (100%) diff --git "a/LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/DSLR.py" "b/LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/DSLR.py" new file mode 100644 index 0000000..7858b38 --- /dev/null +++ "b/LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/DSLR.py" @@ -0,0 +1,50 @@ +# BOJ 9019 +import sys +from collections import deque +input = sys.stdin.readline + +for _ in range(int(input())): + A, B = map(int,input().split()) + + visited = [False] * (10001) + queue = deque([(A,'')]) + visited[A] = True + +# 수식 참고 https://velog.io/@hamsangjin/%EB%B0%B1%EC%A4%80-9019%EB%B2%88-DSLR-%ED%8C%8C%EC%9D%B4%EC%8D%AC + while queue: + num, order = queue.popleft() + + if num == B: + print(order) + break + + # D: D 는 n을 두 배로 바꾼다. + # 결과 값이 9999 보다 큰 경우에는 10000 으로 나눈 나머지를 취한다. + # 그 결과 값(2n mod 10000)을 레지스터에 저장 + D = num * 2 % 10000 + if not visited[D]: + visited[D] = True + queue.append((D, order + 'D')) + + # S: S 는 n에서 1 을 뺀 결과 n-1을 레지스터에 저장한다. + # n이 0 이라면 9999 가 대신 레지스터에 저장 + S = (num - 1) % 10000 + if not visited[S]: + visited[S] = True + queue.append((S, order + 'S')) + + # L: L 은 n의 각 자릿수를 왼편으로 회전시켜 그 결과를 레지스터에 저장한다. + # 연산이 끝나면 레지스터에 저장된 네 자릿수는 왼편부터 d2, d3, d4, d1이 된다 + # 첫번째 자리를 끝으로 보내버리도록 + L = num // 1000 + (num % 1000)*10 + if not visited[L]: + visited[L] = True + queue.append((L, order + 'L')) + + # R: R 은 n의 각 자릿수를 오른편으로 회전시켜 그 결과를 레지스터에 저장한다. + # 이 연산이 끝나면 레지스터에 저장된 네 자릿수는 왼편부터 d4, d1, d2, d3이 된다. + # 마지막 숫자 데려오기 + R = num // 10 + (num % 10) * 1000 + if not visited[R]: + visited[R] = True + queue.append((R, order + 'R')) \ No newline at end of file diff --git "a/LJEDD2/2024-2/\352\271\212\354\235\264/\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211(DFS/BFS)/\354\227\254\355\226\211\352\262\275\353\241\234.py" "b/LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/\354\227\254\355\226\211\352\262\275\353\241\234.py" similarity index 100% rename from "LJEDD2/2024-2/\352\271\212\354\235\264/\353\204\210\353\271\204 \354\232\260\354\204\240 \355\203\220\354\203\211(DFS/BFS)/\354\227\254\355\226\211\352\262\275\353\241\234.py" rename to "LJEDD2/2024-2/\353\204\210\353\271\204\354\232\260\354\204\240\355\203\220\354\203\211(BFS)/\354\227\254\355\226\211\352\262\275\353\241\234.py" From 10284966e7b7bc90fafb9c785ce3a50f955dbc84 Mon Sep 17 00:00:00 2001 From: ljedd2 Date: Sat, 2 Nov 2024 21:40:47 +0900 Subject: [PATCH 16/16] 2024-11-02 --- LJEDD2/2024-2/README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/LJEDD2/2024-2/README.md b/LJEDD2/2024-2/README.md index 0659f23..9b55d03 100644 --- a/LJEDD2/2024-2/README.md +++ b/LJEDD2/2024-2/README.md @@ -17,4 +17,5 @@ | 13차시 | 2024.09.25 | 플로이드 워셜 | 친구 | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/167) | | 14차시 | 2024.09.28 | 큐 | 카드1 | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/170) | | 15차시 | 2024.10.02 | 브루트포스 | 세 개의 소수 문제 | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/174) | -| 16차시 | 2024.10.05 | 그리디 | 마지막 문제 | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/179) | \ No newline at end of file +| 16차시 | 2024.10.05 | 그리디 | 마지막 문제 | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/179) | +| 17차시 | 2024.11.02 | 너비우선탐색(BFS) | DSLR | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-4/pull/185) | \ No newline at end of file