From 33ec48e369cf2b4e03f051edb47eab21c92a06fb Mon Sep 17 00:00:00 2001 From: SSUM <116950962+ssum21@users.noreply.github.com> Date: Sun, 16 Feb 2025 14:21:23 +0900 Subject: [PATCH] =?UTF-8?q?[level=202]=20Title:=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,=20Ti?= =?UTF-8?q?me:=201866.42=20ms,=20Memory:=2010.2=20MB=20-BaekjoonHub?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../2/150368. 이모티콘 할인행사/README.md | 4 +- .../150368. 이모티콘 할인행사/이모티콘 할인행사.py | 78 ++++++------------- 2 files changed, 24 insertions(+), 58 deletions(-) diff --git a/프로그래머스/2/150368. 이모티콘 할인행사/README.md b/프로그래머스/2/150368. 이모티콘 할인행사/README.md index aa7c1b2..1d87322 100644 --- a/프로그래머스/2/150368. 이모티콘 할인행사/README.md +++ b/프로그래머스/2/150368. 이모티콘 할인행사/README.md @@ -1,6 +1,6 @@ # [level 2] 이모티콘 할인행사 - 150368 -[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/150368) +[문제 링크](https://school.programmers.co.kr/learn/courses/30/lessons/150368#qna) ### 성능 요약 @@ -16,7 +16,7 @@ ### 제출 일자 -2025년 02월 16일 14:16:45 +2025년 02월 16일 14:21:21 ### 문제 설명 diff --git a/프로그래머스/2/150368. 이모티콘 할인행사/이모티콘 할인행사.py b/프로그래머스/2/150368. 이모티콘 할인행사/이모티콘 할인행사.py index 49a0aa9..8b64856 100644 --- a/프로그래머스/2/150368. 이모티콘 할인행사/이모티콘 할인행사.py +++ b/프로그래머스/2/150368. 이모티콘 할인행사/이모티콘 할인행사.py @@ -1,59 +1,25 @@ from collections import defaultdict -def DFS(idx, config, emoji_count, poss_ratio): - # 기저 조건: 모든 이모티콘에 대해 할인율을 정했다면 - if idx == emoji_count: - evaluate_config(config) # 이 할인율 조합에 대해 사용자 시뮬레이션 - return - - # 백트래킹: 각 이모티콘에 대해 가능한 모든 할인율 시도 - for discount in poss_ratio: - config.append(discount) # 현재 이모티콘에 discount 할당 - DFS(idx + 1, config, emoji_count, poss_ratio) # 다음 이모티콘으로 진행 - config.pop() # 할당 취소(백트래킹) - - -# 전역 변수 (최종 결과) -max_plus = 0 -max_sales = 0 - -def evaluate_config(config): - global max_plus, max_sales - plus_count = 0 - sales = 0 - # 각 사용자를 순회 - for min_discount, price_threshold in users: # users는 전역 또는 매개변수로 전달 - total_cost = 0 - # 모든 이모티콘에 대해 할인율과 할인 가격 계산 - for i in range(len(emoticons)): - discount = config[i] - # 사용자가 관심 있는 할인율만 구매 (예: discount >= min_discount) - if discount >= min_discount: - discounted_price = emoticons[i] * (100 - discount) // 100 - total_cost += discounted_price - # 기준 가격에 따른 플러스 가입 여부 결정 - if total_cost >= price_threshold: - plus_count += 1 - else: - sales += total_cost - - # 전역 결과 갱신 (가입자 우선, 매출액 두번째) - if plus_count > max_plus or (plus_count == max_plus and sales > max_sales): - max_plus = plus_count - max_sales = sales - - - -def solution(users_input, emoticons_input): - global users, emoticons, max_plus, max_sales - users = users_input - emoticons = emoticons_input - max_plus = 0 - max_sales = 0 - +def solution(users, emoticons): + answer = [] poss_ratio = [40, 30, 20, 10] - emoji_count = len(emoticons) - - DFS(0, [], emoji_count, poss_ratio) - - return [max_plus, max_sales] + emoticons.sort() + sum_emoticons = sum(emoticons) + emoti_ratio = dict() + index=0 + for each in emoticons: + emoti_ratio[index]=[] + emoti_ratio[index].append(each) + for i in range(1, 5): + emoti_ratio[index].append(each-(each*i//10)) + index+=1 + + + for ratio, price in users: + if(sum_emoticons*6//10 < price) + now_ratio = 40 + while now_ratio>=ratio + + print(emoti_ratio) + + return answer \ No newline at end of file