From b59a1c53afd6be9982c6331c7d1b4829ba3e6159 Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 17:06:31 +0900 Subject: [PATCH 1/7] =?UTF-8?q?[BOJ]=201450=20-=20=EB=83=85=EC=83=89?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ByteAurora/20230727/1450.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 ByteAurora/20230727/1450.py diff --git a/ByteAurora/20230727/1450.py b/ByteAurora/20230727/1450.py new file mode 100644 index 0000000..b92c16f --- /dev/null +++ b/ByteAurora/20230727/1450.py @@ -0,0 +1,32 @@ +from bisect import bisect_right + + +def get_possible_cases(weights): + cases = [0] + for i in weights: + for j in range(len(cases)): + cases.append(cases[j] + i) + return cases + + +def get_possible_grouping_count(item_count, bag_size, weights): + weight_group1 = weights[:item_count // 2] + weight_group2 = weights[item_count // 2:] + + group1_cases = get_possible_cases(weight_group1) + group2_cases = get_possible_cases(weight_group2) + + group2_cases.sort() + + result = 0 + for group1_case in group1_cases: + if bag_size - group1_case >= 0: + result += bisect_right(group2_cases, bag_size - group1_case) + + return result + + +N, C = map(int, input().split()) +weights = list(map(int, input().split())) + +print(get_possible_grouping_count(N, C, weights)) From cb6a464715ee4d8a3f0010112bb3cfaee586448c Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 17:07:14 +0900 Subject: [PATCH 2/7] =?UTF-8?q?[PGS]=20138476=20-=20=EA=B7=A4=20=EA=B3=A0?= =?UTF-8?q?=EB=A5=B4=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ByteAurora/20230810/138476.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 ByteAurora/20230810/138476.py diff --git a/ByteAurora/20230810/138476.py b/ByteAurora/20230810/138476.py new file mode 100644 index 0000000..823450c --- /dev/null +++ b/ByteAurora/20230810/138476.py @@ -0,0 +1,20 @@ +def solution(k, tangerine): + answer = 0 + mandarins = {} + + for size in tangerine: + if size in mandarins: + mandarins[size] += 1 + else: + mandarins[size] = 1 + + selected_count = 0 + + for size, count in sorted(mandarins.items(), key=lambda x: x[1], reverse=True): + selected_count += count + answer += 1 + + if selected_count >= k: + break + + return answer From 225aa4e231b732d7010ecbfb325ae2beb41164bb Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 17:07:36 +0900 Subject: [PATCH 3/7] =?UTF-8?q?[PGS]=20154539=20-=20=EB=92=A4=EC=97=90=20?= =?UTF-8?q?=EC=9E=88=EB=8A=94=20=ED=81=B0=20=EC=88=98=20=EC=B0=BE=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ByteAurora/20230810/154539.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 ByteAurora/20230810/154539.py diff --git a/ByteAurora/20230810/154539.py b/ByteAurora/20230810/154539.py new file mode 100644 index 0000000..a22599e --- /dev/null +++ b/ByteAurora/20230810/154539.py @@ -0,0 +1,29 @@ +# 아래는 처음 풀었던 방법 +# def find_nearest_big_number(numbers): +# for number in numbers[1:]: +# if numbers[0] < number: +# return number +# +# return -1 +# +# +# def solution(numbers): +# answer = [] +# +# for idx in range(len(numbers)): +# answer.append(find_nearest_big_number(numbers[idx:])) +# +# return answer + +# 스택을 이용하여 푼 방법 +def solution(numbers): + answer = [-1 for _ in range(len(numbers))] + stack = [] + + for idx, number in enumerate(numbers): + while stack and number > numbers[stack[-1]]: # 스택이 비어있지 않고, 현재 숫자가 스택의 마지막 숫자보다 큰 경우 + answer[stack.pop()] = number + + stack.append(idx) + + return answer From ca313d08db39554a710a1371ef822452f1a9940f Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 18:47:54 +0900 Subject: [PATCH 4/7] =?UTF-8?q?[PGS]=20150368=20-=20=EC=9D=B4=EB=AA=A8?= =?UTF-8?q?=ED=8B=B0=EC=BD=98=20=ED=95=A0=EC=9D=B8=ED=96=89=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ByteAurora/20230810/150368.py | 51 +++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ByteAurora/20230810/150368.py diff --git a/ByteAurora/20230810/150368.py b/ByteAurora/20230810/150368.py new file mode 100644 index 0000000..7c782ab --- /dev/null +++ b/ByteAurora/20230810/150368.py @@ -0,0 +1,51 @@ +possible_discounts = [10, 20, 30, 40] + + +def calculate_subscription_revenue(users, emoticons, discounts): + # 각 이모티콘의 할인된 가격 계산 + discounted_prices = [(1 - discounts[i] * 0.01) * emoticons[i] for i in range(len(emoticons))] + + total_sales = 0 + subscribe_count = 0 + + for user in users: # 모든 사용자에 대해 현재 할인 비율을 적용했을 때의 구독자 수와 매출 계산 + min_discount_rate, max_spendable_amount = user + discounted_total_emoticon_cost = 0 + + for idx in range(len(emoticons)): + if discounts[idx] >= min_discount_rate: + # 할인율이 사용자의 최소 요구 할인율보다 큰거나 같은 경우 + discounted_total_emoticon_cost += discounted_prices[idx] + + if discounted_total_emoticon_cost >= max_spendable_amount: + # 할인된 이모티콘 전체 가격이 사용자의 최대 구매 가능 금액보다 크거나 같은 경우 + # => 서비스 구독 + subscribe_count += 1 + else: + # 할인된 이모티콘 전체 가격이 사용자의 최대 구매 가능 금액보다 작은 경우 + # => 할인된 이모티콘 구매 + total_sales += discounted_total_emoticon_cost + + return subscribe_count, total_sales + + +def search_best_discount(users, emoticons, current_discounts): + if len(current_discounts) == len(emoticons): # 모든 이모티콘에 할인율 적용완료 시 + return calculate_subscription_revenue(users, emoticons, current_discounts) + + best_subscribe_count = -1 + best_sales = -1 + + for discount in possible_discounts: # 가능한 할인율을 각각의 이모티콘에 적용 + current_result = search_best_discount(users, emoticons, current_discounts + [discount]) + + if current_result[0] > best_subscribe_count or ( + current_result[0] == best_subscribe_count and current_result[1] > best_sales): + # 구독자 수가 더 많거나, 구독자 수가 같은 경우 매출이 더 큰 경우 + best_subscribe_count, best_sales = current_result + + return [best_subscribe_count, int(best_sales)] + + +def solution(users, emoticons): + return search_best_discount(users, emoticons, []) \ No newline at end of file From 31038838987203245f97252776d5de61c9ae3c03 Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 20:08:40 +0900 Subject: [PATCH 5/7] =?UTF-8?q?[PGS]=20150368=20-=20=EC=9D=B4=EB=AA=A8?= =?UTF-8?q?=ED=8B=B0=EC=BD=98=20=ED=95=A0=EC=9D=B8=ED=96=89=EC=82=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 기존의 재귀를 통한 조합 생성 대신 product를 이용한 방식으로 변경 --- ByteAurora/20230810/150368.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ByteAurora/20230810/150368.py b/ByteAurora/20230810/150368.py index 7c782ab..1672036 100644 --- a/ByteAurora/20230810/150368.py +++ b/ByteAurora/20230810/150368.py @@ -1,3 +1,5 @@ +from itertools import product + possible_discounts = [10, 20, 30, 40] @@ -29,23 +31,20 @@ def calculate_subscription_revenue(users, emoticons, discounts): return subscribe_count, total_sales -def search_best_discount(users, emoticons, current_discounts): - if len(current_discounts) == len(emoticons): # 모든 이모티콘에 할인율 적용완료 시 - return calculate_subscription_revenue(users, emoticons, current_discounts) - +def search_best_discount(users, emoticons): best_subscribe_count = -1 best_sales = -1 - for discount in possible_discounts: # 가능한 할인율을 각각의 이모티콘에 적용 - current_result = search_best_discount(users, emoticons, current_discounts + [discount]) + for discounts in product(possible_discounts, repeat=len(emoticons)): # 가능한 할인율을 각각의 이모티콘에 적용 + current_subscribe_count, current_sales = calculate_subscription_revenue(users, emoticons, discounts) - if current_result[0] > best_subscribe_count or ( - current_result[0] == best_subscribe_count and current_result[1] > best_sales): + if current_subscribe_count > best_subscribe_count or ( + current_subscribe_count == best_subscribe_count and current_sales > best_sales): # 구독자 수가 더 많거나, 구독자 수가 같은 경우 매출이 더 큰 경우 - best_subscribe_count, best_sales = current_result + best_subscribe_count, best_sales = current_subscribe_count, current_sales - return [best_subscribe_count, int(best_sales)] + return [best_subscribe_count, best_sales] def solution(users, emoticons): - return search_best_discount(users, emoticons, []) \ No newline at end of file + return search_best_discount(users, emoticons) From 42123455f77db0ed5814af304df24d25485edbfc Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 21:59:38 +0900 Subject: [PATCH 6/7] =?UTF-8?q?[PGS]=2092342=20-=20=EC=96=91=EA=B6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ByteAurora/20230810/92342.py | 51 ++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 ByteAurora/20230810/92342.py diff --git a/ByteAurora/20230810/92342.py b/ByteAurora/20230810/92342.py new file mode 100644 index 0000000..7ee2a46 --- /dev/null +++ b/ByteAurora/20230810/92342.py @@ -0,0 +1,51 @@ +score_board_size = 10 + + +def get_ryan_hit_combinations(arrow_count, length=score_board_size + 1): + if length == 1: + return [[arrow_count]] + + ryan_hit_combinations = [] + + for i in range(arrow_count + 1): + for combination in get_ryan_hit_combinations(arrow_count - i, length - 1): + ryan_hit_combinations.append([i] + combination) + + return ryan_hit_combinations + + +def check_ryan_win(apeach_target_hits, ryan_target_hits): + apeach_score = 0 + ryan_score = 0 + + for idx in range(0, score_board_size + 1): + score = score_board_size - idx + if apeach_target_hits[score] == 0 and ryan_target_hits[score] == 0: + continue + elif apeach_target_hits[score] >= ryan_target_hits[score]: + apeach_score += (score_board_size - score) + elif apeach_target_hits[score] < ryan_target_hits[score]: + ryan_score += (score_board_size - score) + + return ryan_score - apeach_score + + +def solution(n, info): + answer = [-1] + best_score_diff = -1 + + for ryan_target_hits in get_ryan_hit_combinations(n): + score_diff = check_ryan_win(info, ryan_target_hits) + + if score_diff > 0: + if score_diff > best_score_diff: + answer = ryan_target_hits + best_score_diff = score_diff + elif score_diff == best_score_diff: + if ''.join(map(str, answer)) > ''.join(map(str, ryan_target_hits)): + answer = ryan_target_hits + + return answer + + +print(solution(9, [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1])) From fa8395b9e7b4e161a1a60f8cfa7c8e013dd4af36 Mon Sep 17 00:00:00 2001 From: Sohn Young Jin Date: Thu, 10 Aug 2023 21:59:47 +0900 Subject: [PATCH 7/7] =?UTF-8?q?[PGS]=2092342=20-=20=EC=96=91=EA=B6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ByteAurora/20230810/92342.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/ByteAurora/20230810/92342.py b/ByteAurora/20230810/92342.py index 7ee2a46..e06be6c 100644 --- a/ByteAurora/20230810/92342.py +++ b/ByteAurora/20230810/92342.py @@ -46,6 +46,3 @@ def solution(n, info): answer = ryan_target_hits return answer - - -print(solution(9, [0, 0, 1, 2, 0, 1, 1, 1, 1, 1, 1]))