From f3782a014c3111e71374dd2155ed0d92605a34d1 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Tue, 20 Aug 2024 16:40:22 +0900 Subject: [PATCH 1/4] 2024-08-20 --- .../\354\271\234\352\265\254\353\271\204.py" | 38 +++++++++++++++++++ H0ngJu/README.md | 1 + 2 files changed, 39 insertions(+) create mode 100644 "H0ngJu/DFS/\354\271\234\352\265\254\353\271\204.py" diff --git "a/H0ngJu/DFS/\354\271\234\352\265\254\353\271\204.py" "b/H0ngJu/DFS/\354\271\234\352\265\254\353\271\204.py" new file mode 100644 index 00000000..4eaac63b --- /dev/null +++ "b/H0ngJu/DFS/\354\271\234\352\265\254\353\271\204.py" @@ -0,0 +1,38 @@ +import sys +from collections import deque, defaultdict + +def input() : return sys.stdin.readline().rstrip() + +N, M, k = map(int, input().split()) +friend_money = list(map(int, input().split())) +relation = defaultdict(set) +visited = [0] * N +total = 0 + +for _ in range(M): + a, b = map(int, input().split()) + relation[a-1].add(b-1) + relation[b-1].add(a-1) + +for i in range(N): + if not visited[i]: + visited[i] = True + friends = [] + q = deque([i]) + + while q: + f = q.popleft() + friends.append(f) + for p in relation[f]: + if not visited[p]: + visited[p] = True + q.append(p) + + if friends: + cost = min(friend_money[friend] for friend in friends) + total += cost + +if total <= k: + print(total) +else: + print("Oh no") diff --git a/H0ngJu/README.md b/H0ngJu/README.md index 4f76049a..879f0716 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -25,5 +25,6 @@ | 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | | 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | +| 25차시 | 2024.08.17 | DFS | [친구비](https://www.acmicpc.net/problem/16562) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/234 | --- From 64cefd05b4018ce0db10bd9763ca17fffa68eab1 Mon Sep 17 00:00:00 2001 From: tgyuuAn Date: Wed, 21 Aug 2024 02:12:46 +0900 Subject: [PATCH 2/4] 71-tgyuuAn --- tgyuuAn/README.md | 1 + ...41\353\213\250\353\263\264\353\217\204.py" | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 "tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\232\241\353\213\250\353\263\264\353\217\204.py" diff --git a/tgyuuAn/README.md b/tgyuuAn/README.md index 73034d56..6e403df7 100644 --- a/tgyuuAn/README.md +++ b/tgyuuAn/README.md @@ -77,4 +77,5 @@ | 68차시 | 2024.08.06 | 그리디 | 가희와 탑 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/226 | 69차시 | 2024.08.10 | 누적합, 수학 | 1의 개수 세기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/228 | 70차시 | 2024.08.16 | 스택 | 탑 보기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/232 +| 71차시 | 2024.08.20 | 다익스트라 | 다익스트라 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/235 --- diff --git "a/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\232\241\353\213\250\353\263\264\353\217\204.py" "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\232\241\353\213\250\353\263\264\353\217\204.py" new file mode 100644 index 00000000..a7cec57d --- /dev/null +++ "b/tgyuuAn/\353\213\244\354\235\265\354\212\244\355\212\270\353\235\274/\355\232\241\353\213\250\353\263\264\353\217\204.py" @@ -0,0 +1,40 @@ +from collections import defaultdict +from heapq import * +import sys + +def input(): return sys.stdin.readline().rstrip() +MAX = 100_000 * 700_000 + 1 +N, M = map(int, input().split()) + +graph = defaultdict(lambda : defaultdict(list)) + +for idx in range(1,M+1): + start, destination = map(int, input().split()) + graph[start][destination].append(idx) + graph[destination][start].append(idx) + +costs = [MAX for _ in range(N+1)] +visited = set() +heap = [(0, 1)] +while heap: + now_cost, now_idx = heappop(heap) + + if now_idx in visited: continue + visited.add(now_idx) + + if costs[now_idx] <= now_cost: continue + costs[now_idx] = now_cost + + if now_idx == N: break + + for neighbor in graph[now_idx]: + if neighbor in visited: continue + + for neighbor_idx in graph[now_idx][neighbor]: + + real_idx = now_cost % M + if real_idx < neighbor_idx: + heappush(heap, (neighbor_idx - real_idx + now_cost, neighbor)) + else: + heappush(heap, (now_cost + M - real_idx + neighbor_idx, neighbor)) +print(costs[-1]) \ No newline at end of file From 954dd483726e5f604268d2f1897782c2b35e9656 Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sun, 25 Aug 2024 00:52:58 +0900 Subject: [PATCH 3/4] 2024-08-25 --- H0ngJu/README.md | 6 ++++-- ...40\354\236\205\354\202\254\354\233\220.py" | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 "H0ngJu/\352\267\270\353\246\254\353\224\224/\354\213\240\354\236\205\354\202\254\354\233\220.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index d0ad3845..9e6c102d 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -24,7 +24,9 @@ | 20차시 | 2024.06.03 | 백트래킹 | [스타트와 링크](https://www.acmicpc.net/problem/14889) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/206 | | 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | | 22차시 | 2024.08.06 | 해시 | [의상](https://school.programmers.co.kr/learn/courses/30/lessons/42578) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/224 | -| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | -| 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | +| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | +| 24차시 | 2024.08.17 | BFS | [아기상어](https://www.acmicpc.net/problem/16236) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/233 | + +| 26차시 | 2024.08.24 | 그리디 | [신입사원](https://www.acmicpc.net/problem/1946) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/237 | --- diff --git "a/H0ngJu/\352\267\270\353\246\254\353\224\224/\354\213\240\354\236\205\354\202\254\354\233\220.py" "b/H0ngJu/\352\267\270\353\246\254\353\224\224/\354\213\240\354\236\205\354\202\254\354\233\220.py" new file mode 100644 index 00000000..21d9e280 --- /dev/null +++ "b/H0ngJu/\352\267\270\353\246\254\353\224\224/\354\213\240\354\236\205\354\202\254\354\233\220.py" @@ -0,0 +1,19 @@ +import sys + +def input(): return sys.stdin.readline().rstrip() + +T = int(input()) + +for _ in range(T): + N = int(input()) + apply = [list(map(int, input().split())) for _ in range(N)] + apply = sorted(apply) + top = 0 + cnt = 1 + + for i in range(1, N): + if apply[i][1] < apply[top][1]: + top = i + cnt += 1 + + print(cnt) \ No newline at end of file From 41ca80b9cbaf8244726af28efe78071ec2a7cc25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D=7CMinseok=20Kim?= Date: Mon, 26 Aug 2024 14:58:44 +0900 Subject: [PATCH 4/4] 2024-08-21 solved (#236) --- alstjr7437/BFS/DSLR.py | 36 ++++++++++++++++++++++++++++++++++++ alstjr7437/README.md | 7 ++++--- 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 alstjr7437/BFS/DSLR.py diff --git a/alstjr7437/BFS/DSLR.py b/alstjr7437/BFS/DSLR.py new file mode 100644 index 00000000..4a953c7d --- /dev/null +++ b/alstjr7437/BFS/DSLR.py @@ -0,0 +1,36 @@ +from collections import deque +import sys + +input = sys.stdin.readline + +T = int(input()) + +def command(register, cmd): + if cmd == 0: + return ((register * 2) % 10000, "D") + elif cmd == 1: + return (9999 if register == 0 else register - 1, "S") + elif cmd == 2: + return (register % 1000 * 10 + register // 1000, "L") + elif cmd == 3: + return (register // 10 + (register % 10) * 1000, "R") + +for _ in range(T): + A, B = map(int, input().split()) + + visited = [False] * 10000 + visited[A] = True + + queue = deque([(A, "")]) + while queue: + cur, result = queue.popleft() + + if cur == B: + print(result) + break + + for i in range(4): + register, cmd = command(cur, i) + if not visited[register]: + visited[register] = True + queue.append((register, result + cmd)) \ No newline at end of file diff --git a/alstjr7437/README.md b/alstjr7437/README.md index ecfd040c..bd7fb9fd 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -31,6 +31,7 @@ | 27차시 | 2024.05.26 | 우선순위 큐 | 이중 우선순위 큐 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/198 | | 28차시 | 2024.05.30 | 브루트 포스 | 카잉 달력 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/203 | | 29차시 | 2024.06.11 | 이분 탐색 | 나무 자르기 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/210 | -| 30차시 | 2024.06.19 | 방 번호 | 구현 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 | -| 31차시 | 2024.06.19 | 게임 맵 최단거리 | BFS | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 | -| 32차시 | 2024.08.15 | 과일 탕후루 | 투 포인터 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 | \ No newline at end of file +| 30차시 | 2024.06.19 | 구현 | 방 번호 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/211 | +| 31차시 | 2024.06.19 | BFS | 게임 맵 최단거리 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/218 | +| 32차시 | 2024.08.15 | 투 포인터 | 과일 탕후루 | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/230 | +| 33차시 | 2024.08.21 | BFS | DSLR | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/236 | \ No newline at end of file