From 2ee6c1ea33dcb6219bfabc7c399ba1b87a4479fa Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sat, 10 Aug 2024 20:35:50 +0900 Subject: [PATCH 1/2] 2024-08-10 --- H0ngJu/README.md | 3 +- ...44\355\212\270\354\225\250\353\262\224.py" | 33 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 "H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" diff --git a/H0ngJu/README.md b/H0ngJu/README.md index c76b9d05..2fbd2655 100644 --- a/H0ngJu/README.md +++ b/H0ngJu/README.md @@ -22,7 +22,8 @@ | 18차시 | 2024.05.26 | DFS | [계란으로 계란치기](https://www.acmicpc.net/problem/16987) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/199 | | 19차시 | 2024.05.31 | DP | [합분해](https://www.acmicpc.net/problem/2225) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/202 | | 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 | -| 21차시 | 2024.06.07 | 그리디 | [행복 유치원](https://www.acmicpc.net/problem/13164) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/208 | +| 23차시 | 2024.08.10 | 해시 | [베스트앨범](https://school.programmers.co.kr/learn/courses/30/lessons/42579) | https://github.com/AlgoLeadMe/AlgoLeadMe-1/pull/227 | --- diff --git "a/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" "b/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" new file mode 100644 index 00000000..00012820 --- /dev/null +++ "b/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" @@ -0,0 +1,33 @@ +genres = ["classic", "pop", "classic", "classic", "pop"] +plays = [500, 600, 150, 800, 2500] +answer = [] + +dic = {} +info = {} + +for i in range(len(genres)): + g = genres[i] + p = plays[i] + + info[i] = g + + if g in dic: + dic[g] += p + else: + dic[g] = p + +best_g = sorted(dic.items(), key=lambda x: x[1], reverse=True) + +for g, _ in best_g: + best_album = [(plays[i], i) for i in range(len(genres)) if genres[i] == g] + for i in range(len(best_album)): + for j in range(i+1, len(best_album)): + if best_album[j][0] > best_album[i][0]: #재생수가 작은 경우 + best_album[i], best_album[j] = best_album[j], best_album[i] + elif best_album[j][0] == best_album[i][0] and best_album[j][1] < best_album[i][1]: #idx가 작은 경우 + best_album[i], best_album[j] = best_album[j], best_album[i] + + answer.extend([x[1] for x in best_album[:2]]) + + +print(answer) \ No newline at end of file From 9c598c75ed2ffe30a3e50afcbcc0148e1619af9b Mon Sep 17 00:00:00 2001 From: H0ngJu Date: Sat, 10 Aug 2024 21:08:04 +0900 Subject: [PATCH 2/2] 2024-08-10 --- ...0\354\212\244\355\212\270\354\225\250\353\262\224.py" | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git "a/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" "b/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" index 00012820..2a7eb9a6 100644 --- "a/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" +++ "b/H0ngJu/\353\262\240\354\212\244\355\212\270\354\225\250\353\262\224.py" @@ -1,6 +1,7 @@ -genres = ["classic", "pop", "classic", "classic", "pop"] -plays = [500, 600, 150, 800, 2500] +genres = ["classic", "pop", "classic", "classic", "pop", "ex", "ex"] +plays = [500, 600, 150, 800, 2500, 900, 400] answer = [] +f = 0 dic = {} info = {} @@ -19,15 +20,15 @@ best_g = sorted(dic.items(), key=lambda x: x[1], reverse=True) for g, _ in best_g: + if f == 2: break best_album = [(plays[i], i) for i in range(len(genres)) if genres[i] == g] for i in range(len(best_album)): for j in range(i+1, len(best_album)): if best_album[j][0] > best_album[i][0]: #재생수가 작은 경우 best_album[i], best_album[j] = best_album[j], best_album[i] - elif best_album[j][0] == best_album[i][0] and best_album[j][1] < best_album[i][1]: #idx가 작은 경우 - best_album[i], best_album[j] = best_album[j], best_album[i] answer.extend([x[1] for x in best_album[:2]]) + f += 1 print(answer) \ No newline at end of file