From a81b11589febc7e54f5a73fcfefe823691d61176 Mon Sep 17 00:00:00 2001 From: kdongsu5509 Date: Thu, 15 Aug 2024 07:50:24 +0000 Subject: [PATCH 1/7] Auto Update README.md file --- README.md | 12 ++++++------ total_push_cnt.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 32b9cdb..cec1c8b 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,11 @@ Python : 3    Java : 0    C : 0     C++ : 0     C# : 0 김성원 - 76 - 76 - 24 - -24000 - Python : 76    Java : 0    C : 0     C++ : 0     C# : 0 + 77 + 77 + 23 + -23000 + Python : 77    Java : 0    C : 0     C++ : 0     C# : 0 김희수 21 @@ -71,7 +71,7 @@ Python : 12    Java : 0    C : 0     C++ : 0     C# : 0
-총 Push 횟수 : 193회 +총 Push 횟수 : 194회 # 업로드 방법 ### 1. 파일명 diff --git a/total_push_cnt.txt b/total_push_cnt.txt index 2455a46..205a12b 100644 --- a/total_push_cnt.txt +++ b/total_push_cnt.txt @@ -1 +1 @@ -193 +194 From 2cae50d0eb6e0198f8248513d6f3876099d26793 Mon Sep 17 00:00:00 2001 From: HyeonjinBae Date: Fri, 16 Aug 2024 00:30:40 +0900 Subject: [PATCH 2/7] 20240815 --- HJBAE/21to30/25.py | 41 ++++++++++++++++++++++++++++++++++ HJBAE/21to30/26.py | 30 +++++++++++++++++++++++++ HJBAE/21to30/27.py | 55 ++++++++++++++++++++++++++++++++++++++++++++++ HJBAE/21to30/28.py | 22 +++++++++++++++++++ HJBAE/21to30/29.py | 42 +++++++++++++++++++++++++++++++++++ 5 files changed, 190 insertions(+) create mode 100644 HJBAE/21to30/25.py create mode 100644 HJBAE/21to30/26.py create mode 100644 HJBAE/21to30/27.py create mode 100644 HJBAE/21to30/28.py create mode 100644 HJBAE/21to30/29.py diff --git a/HJBAE/21to30/25.py b/HJBAE/21to30/25.py new file mode 100644 index 0000000..d3d581f --- /dev/null +++ b/HJBAE/21to30/25.py @@ -0,0 +1,41 @@ +""" +order은 손님들이 주문하던 단품메뉴들 +최소 2명 이상의 손님으로부터 주문된 단품 메뉴 조합에 대해서만 코스요리 메뉴 후보에 포함 +course는 추가하고 싶은 단품 메뉴 +""" +from itertools import combinations +from collections import Counter + +def solution(orders, course): + result = [] + + for c in course: + comb_list = [] + + for order in orders: + # 각 주문 알파벳 순으로 정렬 + combinations를 사용해서 주문된 단품 메뉴 조합 생성 + comb_list += combinations(sorted(order), c) + + # 생성된 조합들 Counter 사용해서 셈 -> 각 조합 몇 번 주문되었는지 check + most_common_comb = Counter(comb_list).most_common() + + # 2명 이상 주문한 조합 중 가장 많이 주문한 조합 result에 추가 + result += [comb for comb, count in most_common_comb if count > 1 and count == most_common_comb[0][1]] + + return [''.join(comb) for comb in sorted(result)] + +orders1 = ["ABCFG", "AC", "CDE", "ACDE", "BCFG", "ACDEH"] +course1 = [2, 3, 4] +# result1 = ["AC", "ACDE", "BCFG", "CDE"] + +orders2 = ["ABCDE", "AB", "CD", "ADE", "XYZ", "XYZ", "ACD"] +course2 = [2, 3, 5] +# result2 = ["ACD", "AD", "ADE", "CD", "XYZ"] + +orders3 = ["XYZ", "XWY", "WXA"] +course3 = [2, 3, 4] +# result3 = ["WX", "XY"] + +print(solution(orders1, course1)) +print(solution(orders2, course2)) +print(solution(orders3, course3)) \ No newline at end of file diff --git a/HJBAE/21to30/26.py b/HJBAE/21to30/26.py new file mode 100644 index 0000000..143d0dd --- /dev/null +++ b/HJBAE/21to30/26.py @@ -0,0 +1,30 @@ +""" +이진 트리를 표현한 리스트 nodes를 인자로 받음 +해당 이진 트리에 대하여 전위 순회, 중위 순회, 후위 순회 결과를 반환하는 solution() 함수를 구하시오 +""" +def preorder(nodes, idx): # 전위 순회 + if idx >= len(nodes): + return [] + return [nodes[idx]] + preorder(nodes, 2 * idx + 1) + preorder(nodes, 2 * idx + 2) + +def inorder(nodes, idx): # 중위 순회 + if idx >= len(nodes): + return [] + return inorder(nodes, 2 * idx + 1) + [nodes[idx]] + inorder(nodes, 2 * idx + 2) + +def postorder(nodes, idx): + if idx >= len(nodes): + return [] + return postorder(nodes, 2 * idx + 1) + postorder(nodes, 2 * idx + 2) + [nodes[idx]] + +def solution(nodes): + pre_order = preorder(nodes, 0) + in_order = inorder(nodes, 0) + post_order = postorder(nodes, 0) + return [" ".join(map(str, pre_order)), " ".join(map(str, in_order)), " ".join(map(str, post_order))] + +nodes = [1, 2, 3, 4, 5, 6, 7] +# return = ["1 2 4 5 3 6 7", "4 2 5 1 6 3 7", "4 5 2 6 7 3 1"] + +result = solution(nodes) +print(result) \ No newline at end of file diff --git a/HJBAE/21to30/27.py b/HJBAE/21to30/27.py new file mode 100644 index 0000000..e536bf4 --- /dev/null +++ b/HJBAE/21to30/27.py @@ -0,0 +1,55 @@ +""" +첫 번째 인수 lst를 이용해서 이진 탐색 트리를 생성하고 +두 번째 인수 search_lst에 있는 각 노드를 이진 탐색 트리에서 찾을 수 있는지 확인하여 +True 또는 False를 담은 리스트 result를 반환하는 함수 solution()을 작성 +""" + +class TreeNode: + def __init__(self, value): + self.value = value + self.left = None + self.right = None + +def insert_into_bst(root, value): + if root is None: + return TreeNode(value) # 트리가 비어있으면 새로운 노드 반환 + if value < root.value: # 안비어있으면 왼쪽 or 오른쪽에 삽입 + root.left = insert_into_bst(root.left, value) + else: + root.right = insert_into_bst(root.right, value) + return root + +def search_bst(root, value): # value가 트리에 존재하는지 확인 + if root is None: # 비어있으면 False + return False + if root.value == value: # 같으면 True + return True + elif value < root.value: # 작으면 왼쪽 서브트리 + return search_bst(root.left, value) + else: # 크면 오른쪽 서브트리 + return search_bst(root.right, value) + +def solution(lst, search_lst): # 일단 lst를 이용해서 이진 탐색 트리 생성 + if not lst: # 비어있는 경우 + return [False] * len(search_lst) # search_lst 를 이용해서 True 아니면 False 반환 + + root = None + for value in lst: + root = insert_into_bst(root, value) + + result = [] + for value in search_lst: # search_lst 각 값을 트리에서 검색하고 결과를 result 리스트에 추가 + result.append(search_bst(root, value)) + + return result + +lst1 = [5, 3, 8, 4, 2, 1, 7, 10] +search_lst1 = [1, 2, 5, 6] +# answer1 = [True, True, True, False] + +lst2 = [1, 3, 5, 7, 9] +search_lst2 = [2, 4, 6, 8, 10] +# answer2 = [False, False, False, False, False] + +print(solution(lst1, search_lst1)) +print(solution(lst2, search_lst2)) \ No newline at end of file diff --git a/HJBAE/21to30/28.py b/HJBAE/21to30/28.py new file mode 100644 index 0000000..6d885a3 --- /dev/null +++ b/HJBAE/21to30/28.py @@ -0,0 +1,22 @@ +""" +N명의 참가자에게 1부터 N번의 번호를 차례로 배정 +1vs2 3vs4 ... N-1 vs N 해서 이기면 다음 라운드 진출 +다음 라운드 진출자들 다시 번호 매김 +N : 2^1 이상 2^20 이하인 자연수 (2의 지수로 주어지므로 부전승 X) +A, B : N 이하인 자연수 (A != B) +""" +def solution(N, A, B): + round_num = 1 + while A != B: + A = (A + 1) // 2 + B = (B + 1) // 2 + round_num += 1 + return round_num - 1 + +N = 8 +A = 4 +B = 7 +print(solution(N, A, B)) +# answer = 3 +# 1 -> 1, 2 -> 1, 3 -> 2, 4 -> 2 +# 5 -> 3, 6 -> 3, 7 -> 4, 8 -> 4 \ No newline at end of file diff --git a/HJBAE/21to30/29.py b/HJBAE/21to30/29.py new file mode 100644 index 0000000..25599aa --- /dev/null +++ b/HJBAE/21to30/29.py @@ -0,0 +1,42 @@ +""" +모든 판매원은 칫솔 판매로 생기는 이익에서 10%를 계산해 자신을 조직에 참여시킨 추천인에게 배분 나머지는 자신이 가짐 +모든 판매원은 자신이 조직에 추천하여 가입시킨 판매원의 이익금의 10%를 자신이 가짐 +10% 계산할 때 원 단위에서 자르고, 10% 계산한 금액이 1원 미만이면 분배 X +""" + +# 판매원 얻은 이익 계산하고 10%를 추천인에게 분배 +def distribute_profit(name, profit, parent, earnings): + if name == "-" or profit == 0: # 추천인 "-"이거나 분배할 이익이 1원 미만이면 종료 + return + parent_profit = profit // 10 + earnings[name] += profit - parent_profit + distribute_profit(parent[name], parent_profit, parent, earnings) + + +def solution(enroll, referral, seller, amount): + # 일단 돈 줘야 하는 사람을 key로, 받는 사람을 value로 대응시켜서 저장 + parent = {enroll[i] : referral[i] for i in range(len(enroll))} # 추천인 저장 + earnings = {name : 0 for name in enroll} # 각 seller 총 수익 저장하는 dictionary + + for i in range(len(seller)): + profit = amount[i] * 100 + seller_info = seller[i] + distribute_profit(seller[i], profit, parent, earnings) + + return [earnings[name]for name in enroll] + + +enroll = ["john", "mary", "edward", "sam", "emily", "jaimie", "tod", "young"] +referral = ["-", "-", "mary", "edward", "mary", "mary", "jaimie", "edward"] + +seller1 = ["young", "john", "tod", "emily", "mary"] +amount1 = [12, 4, 2, 5, 10] + +seller2 = ["sam", "emily", "jaimie", "edward"] +amount2 = [2, 3, 5, 4] +# result1 = [360, 958, 108, 0, 450, 18, 180, 1080] + +print(solution(enroll, referral, seller1, amount1)) +# result2 = [0, 110, 378, 180, 270, 450, 0, 0] + +print(solution(enroll, referral, seller2, amount2)) \ No newline at end of file From fe7aa68a5afad4c761d58bcf62c3ddc4bbb11d5a Mon Sep 17 00:00:00 2001 From: kdongsu5509 Date: Thu, 15 Aug 2024 15:31:03 +0000 Subject: [PATCH 3/7] Auto Update README.md file --- README.md | 12 ++++++------ total_push_cnt.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index cec1c8b..d267adf 100644 --- a/README.md +++ b/README.md @@ -36,11 +36,11 @@ Python : 21    Java : 0    C : 0     C++ : 0     C# : 0 배현진 - 23 - 26 - 77 - -77000 - Python : 26    Java : 0    C : 0     C++ : 0     C# : 0 + 28 + 31 + 72 + -72000 + Python : 31    Java : 0    C : 0     C++ : 0     C# : 0 박지영 45 @@ -71,7 +71,7 @@ Python : 12    Java : 0    C : 0     C++ : 0     C# : 0
-총 Push 횟수 : 194회 +총 Push 횟수 : 195회 # 업로드 방법 ### 1. 파일명 diff --git a/total_push_cnt.txt b/total_push_cnt.txt index 205a12b..6bb2f98 100644 --- a/total_push_cnt.txt +++ b/total_push_cnt.txt @@ -1 +1 @@ -194 +195 From 8a98570f72968bd0289029569634a5766afd7cf6 Mon Sep 17 00:00:00 2001 From: park jiyeong Date: Fri, 16 Aug 2024 01:09:11 +0900 Subject: [PATCH 4/7] 50! --- JYPARK/41to50/50.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 JYPARK/41to50/50.py diff --git a/JYPARK/41to50/50.py b/JYPARK/41to50/50.py new file mode 100644 index 0000000..21eb1cf --- /dev/null +++ b/JYPARK/41to50/50.py @@ -0,0 +1,19 @@ +def solution(n): + def check(ls, new): + for i in range(len(ls)): + if new == ls[i] or (len(ls)-i) == abs(ls[i]-new): + return False + return True + def dfs(n, ls): + if len(ls) == n: + return 1 + cnt = 0 + for i in range(n): + if check(ls, i): + cnt += dfs(n, ls+[i]) + return cnt + + return dfs(n, []) + +n = 4 +print(solution(n)) From f876eedee46b6ad8b32d60aea6f2512c27fc9a73 Mon Sep 17 00:00:00 2001 From: kdongsu5509 Date: Thu, 15 Aug 2024 16:09:36 +0000 Subject: [PATCH 5/7] Auto Update README.md file --- README.md | 12 ++++++------ total_push_cnt.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index d267adf..7f61cbf 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,11 @@ Python : 31    Java : 0    C : 0     C++ : 0     C# : 0 박지영 - 45 - 47 - 55 - -55000 - Python : 40    Java : 0    C : 7     C++ : 0     C# : 0 + 46 + 48 + 54 + -54000 + Python : 41    Java : 0    C : 7     C++ : 0     C# : 0 손시연 12 @@ -71,7 +71,7 @@ Python : 12    Java : 0    C : 0     C++ : 0     C# : 0
-총 Push 횟수 : 195회 +총 Push 횟수 : 196회 # 업로드 방법 ### 1. 파일명 diff --git a/total_push_cnt.txt b/total_push_cnt.txt index 6bb2f98..0f11735 100644 --- a/total_push_cnt.txt +++ b/total_push_cnt.txt @@ -1 +1 @@ -195 +196 From 00c756cfa65488d8e419587fe694338c3cea6415 Mon Sep 17 00:00:00 2001 From: park jiyeong Date: Fri, 16 Aug 2024 01:13:40 +0900 Subject: [PATCH 6/7] 51! --- JYPARK/51to60/51.py | 71 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 JYPARK/51to60/51.py diff --git a/JYPARK/51to60/51.py b/JYPARK/51to60/51.py new file mode 100644 index 0000000..2a1e8b0 --- /dev/null +++ b/JYPARK/51to60/51.py @@ -0,0 +1,71 @@ +def distribution(arrows, score, arrow_per_person=None, idx=0): + if arrow_per_person is None: + arrow_per_person = [0] * score + + if arrows == 0: + return [tuple(arrow_per_person)] + + distributions = [] + + for i in range(idx, score): + if arrows > 0: + arrow_per_person[i] += 1 + next_distributions = distribution(arrows - 1, score, arrow_per_person, i) + distributions.extend(next_distributions) + arrow_per_person[i] -= 1 + + return distributions + +def solution(n, info): + answer = [] + maxv = 0 + real = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0] + all_distributions = distribution(n, 11) + + for temp in all_distributions: + ryan = 0 + muzi = 0 + for i in range(len(temp)): + if temp[i] or info[i]: + if temp[i] > info[i]: + ryan += real[i] + else: + muzi += real[i] + + gap = ryan - muzi + + if gap > maxv: + answer = [] + answer.append(temp) + maxv = gap + elif gap < maxv: + continue + else: + answer.append(temp) + + if not answer: + return [-1] + elif maxv == 0: + return [-1] + + idx = -1 + for i in range(len(answer[0])-1, -1, -1): + maxv = -float('inf') + for a in answer: + if a[i] == 0: + continue + if maxv < a[i]: + maxv = a[i] + if maxv > 0: + idx = i + break + + answer.sort(key = lambda x:-x[idx]) + + return answer[0] + +n, info = 5, [2,1,1,1,0,0,0,0,0,0,0] +n, info = 1, [1,0,0,0,0,0,0,0,0,0,0] +n, info = 9, [0,0,1,2,0,1,1,1,1,1,1] +n, info = 10, [0,0,0,0,0,0,0,0,3,4,3] +print(solution(n, info)) \ No newline at end of file From ade047be4b0ebc9b2f2679cfb10289909c6c80d5 Mon Sep 17 00:00:00 2001 From: kdongsu5509 Date: Thu, 15 Aug 2024 16:13:56 +0000 Subject: [PATCH 7/7] Auto Update README.md file --- README.md | 12 ++++++------ total_push_cnt.txt | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 7f61cbf..e6e8bc5 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,11 @@ Python : 31    Java : 0    C : 0     C++ : 0     C# : 0 박지영 - 46 - 48 - 54 - -54000 - Python : 41    Java : 0    C : 7     C++ : 0     C# : 0 + 47 + 49 + 53 + -53000 + Python : 42    Java : 0    C : 7     C++ : 0     C# : 0 손시연 12 @@ -71,7 +71,7 @@ Python : 12    Java : 0    C : 0     C++ : 0     C# : 0
-총 Push 횟수 : 196회 +총 Push 횟수 : 197회 # 업로드 방법 ### 1. 파일명 diff --git a/total_push_cnt.txt b/total_push_cnt.txt index 0f11735..5381652 100644 --- a/total_push_cnt.txt +++ b/total_push_cnt.txt @@ -1 +1 @@ -196 +197