From 42f8af84093bb5b569ae2a27019a57047a2246a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=84=9D=7CMinseok=20Kim?= Date: Sat, 24 Feb 2024 21:46:03 +0900 Subject: [PATCH 1/3] 2024-02-24 solved --- alstjr7437/README.md | 1 + ...0\353\252\250-\354\260\276\352\270\260.py" | 2 +- ...44\355\212\270\354\225\250\353\262\224.py" | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 "alstjr7437/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" diff --git a/alstjr7437/README.md b/alstjr7437/README.md index 1997ba8..f160926 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -12,4 +12,5 @@ | 8차시 | 2024.02.14 | DP | 평범한 배낭 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/24 | | 9차시 | 2024.02.17 | 그리디 | 전구와 스위치 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/29 | | 10차시 | 2024.02.20 | BFS/DFS | 트리의 부모 찾기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/33 | +| 11차시 | 2024.02.23 | 해시 | 베스트 앨범 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/39 | diff --git "a/alstjr7437/\355\212\270\353\246\254/\355\212\270\353\246\254\354\235\230-\353\266\200\353\252\250-\354\260\276\352\270\260.py" "b/alstjr7437/\355\212\270\353\246\254/\355\212\270\353\246\254\354\235\230-\353\266\200\353\252\250-\354\260\276\352\270\260.py" index 8221840..0e6a5aa 100644 --- "a/alstjr7437/\355\212\270\353\246\254/\355\212\270\353\246\254\354\235\230-\353\266\200\353\252\250-\354\260\276\352\270\260.py" +++ "b/alstjr7437/\355\212\270\353\246\254/\355\212\270\353\246\254\354\235\230-\353\266\200\353\252\250-\354\260\276\352\270\260.py" @@ -43,4 +43,4 @@ def bfs(): bfs() for i in range(2, n+1): - print(visited[i]) + print(visited[i]) \ No newline at end of file diff --git "a/alstjr7437/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" "b/alstjr7437/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" new file mode 100644 index 0000000..98065d6 --- /dev/null +++ "b/alstjr7437/\355\225\264\354\213\234/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" @@ -0,0 +1,30 @@ +def solution(genres, plays): + answer = [] + dict = {} + + # 딕셔너리 만들기 + for i in range(len(genres)): + if genres[i] not in dict : + dict[genres[i]] = [[plays[i], i]] + else : + dict[genres[i]].append([plays[i],i]) + + # 딕셔너리 안에 재생회수로 재정렬 + for genres, plays in dict.items(): + dict[genres] = sorted(plays, key=lambda x: x[0], reverse=True) + + # 각 장르 총합 계산 + totals = {i: sum(j[0] for j in songs) for i, songs in dict.items()} + + # 총합 기준으로 딕셔너리 순서 변경 + sorted_data = {k: v for k, v in sorted(dict.items(), key=lambda item: totals[item[0]], reverse=True)} + + + # 정답 인덱스 추가 부분 + for i in sorted_data.values(): + answer.append(i[0][1]) + if len(i) != 1: + answer.append(i[1][1]) + + + return answer \ No newline at end of file From 352af8ceac101ed27c8d033e4bcc46a586a3fa79 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 Feb 2024 15:01:39 +0900 Subject: [PATCH 2/3] =?UTF-8?q?12=EC=B0=A8=20=EB=AC=B8=EC=A0=9C=20?= =?UTF-8?q?=EC=84=A0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\241\260\354\235\230-\355\230\270\354\210\230.py" | 8 ++++++++ alstjr7437/README.md | 2 ++ 2 files changed, 10 insertions(+) create mode 100644 "alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" diff --git "a/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" "b/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" new file mode 100644 index 0000000..12b7a31 --- /dev/null +++ "b/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" @@ -0,0 +1,8 @@ +r, c = map(int, input().split()) + +river = [] + +for i in range(r): + river.append(list(map(input().split()))) + +print(river) \ No newline at end of file diff --git a/alstjr7437/README.md b/alstjr7437/README.md index f160926..f9e8c81 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -13,4 +13,6 @@ | 9차시 | 2024.02.17 | 그리디 | 전구와 스위치 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/29 | | 10차시 | 2024.02.20 | BFS/DFS | 트리의 부모 찾기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/33 | | 11차시 | 2024.02.23 | 해시 | 베스트 앨범 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/39 | +| 12차시 | 2024.02.26 | BFS | 백조의 호수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/41 | + From 499bae6cdbc74dd63df43e050bdcf2c7394f3790 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 Feb 2024 22:57:33 +0900 Subject: [PATCH 3/3] 2024-02-26 solved --- ...0\354\235\230-\355\230\270\354\210\230.py" | 86 ++++++++++++++++++- alstjr7437/README.md | 2 - 2 files changed, 83 insertions(+), 5 deletions(-) diff --git "a/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" "b/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" index 12b7a31..6da86a6 100644 --- "a/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" +++ "b/alstjr7437/BFS/\353\260\261\354\241\260\354\235\230-\355\230\270\354\210\230.py" @@ -1,8 +1,88 @@ +from collections import deque +import sys + +dx = [0,0,-1,1] +dy = [1,-1,0,0] r, c = map(int, input().split()) -river = [] +water1 = deque() +water2 = deque() +visited = [[False] * c for _ in range(r)] + +swan1 = deque() +swan2 = deque() +visited2 = [[False] * c for _ in range(r)] +# 1. 전체 호수 만들기 +river = [] for i in range(r): - river.append(list(map(input().split()))) + river.append(list(input())) + +day_count = 0 + +# 2. 백조 위치 찾기와 물 위치 찾기 +swan = [] +for x in range(c): + for y in range(r): + if river[y][x] == "L": + swan.append([y,x]) + river[y][x] = "." + if river[y][x] == ".": + water1.append([y, x]) + visited[y][x] = True + +# 3. 백조를 큐에 추가 +swan1.append(swan[0]) +visited2[swan[0][0]][swan[0][1]] = True + +# 4. 하루에 한번씩 X 없애기(얼음 없애기) +def break_ice(): + # print("-------") + while water1: + y, x = water1.popleft() + # print(y, x, water1, water2) + river[y][x] = "." + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if nx < 0 or nx >= c or ny < 0 or ny >= r: + continue + if not visited[ny][nx]: + if river[ny][nx] == ".": + water1.append([ny,nx]) + else : + water2.append([ny,nx]) + visited[ny][nx] = True + +# 5. 백조가 만나는지 체크하기 +def check_swan(): + # print("-------") + while swan1 : + y, x = swan1.popleft() + # print(x,y,swan1, swan2) + if y == swan[1][0] and x == swan[1][1]: + print(day_count) + sys.exit() + for i in range(4): + nx = x + dx[i] + ny = y + dy[i] + if nx < 0 or nx >= c or ny < 0 or ny >= r: + continue + if not visited2[ny][nx]: + if river[ny][nx] == "." and visited2[ny][nx] == False: + swan1.append([ny,nx]) + else : + swan2.append([ny,nx]) + visited2[ny][nx] = True + return False + +# 만날때까지 돌리기 +while 1: + break_ice() + water1 = water2 + water2 = deque() -print(river) \ No newline at end of file + check_swan() + swan1 = swan2 + swan2 = deque() + day_count += 1 \ No newline at end of file diff --git a/alstjr7437/README.md b/alstjr7437/README.md index f9e8c81..dbca916 100644 --- a/alstjr7437/README.md +++ b/alstjr7437/README.md @@ -14,5 +14,3 @@ | 10차시 | 2024.02.20 | BFS/DFS | 트리의 부모 찾기 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/33 | | 11차시 | 2024.02.23 | 해시 | 베스트 앨범 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/39 | | 12차시 | 2024.02.26 | BFS | 백조의 호수 | https://github.com/AlgoLeadMe/AlgoLeadMe-6/pull/41 | - -