Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 그래프탐색
- 파이썬
- 트리의지름
- 백준
- DFS
- 프림알고리즘
- 두큐합같게만들기
- 파괴되지않은건물
- 이모티콘할인행사
- 거리두기확인하기
- 자물쇠와열쇠
- 위상정렬
- DP
- 최소스패닝트리
- 다익스트라
- 벽부수고이동하기
- 프로그래머스
- [1차]캐시
- 사이클게임
- BFS
- 큐
- RGB거리2
- 구현
- 징검다리건너기
- 알고리즘
- 섬연결하기
- javascript
- 17404
- 도넛과막대그래프
- 최단경로
Archives
- Today
- Total
블로그 이름 뭐로 하지
[알고리즘/파이썬] 프로그래머스 - 이모티콘 할인행사 본문
문제
https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
풀이
할인율이 10,20,30,40 으로 정해져있다는 말을 못 보고.. ㅠㅠ 그냥 랜덤인줄 알고 풀이가 도저히 떠오르지 않았고... 이게 정말 레벨2가 맞는건지 .. 의심이 갔다. 근데 할인율이 정해져있는 문제였다.ㅎ....
가능한 할인율 조합을 모두 구해서 그 조합따라서 가입자수와 이익을 계산해서 가장 좋은 경우에 값을 저장해두어 출력해주면 된다.
코드
def solution(users, emoticons):
answer = [0, 0]
sale_rate = [10, 20, 30, 40]
sale = []
def dfs(temp, depth):
if depth == len(temp):
sale.append(temp[:])
return
for s in sale_rate:
temp[depth] += s
dfs(temp, depth + 1)
temp[depth] -= s
dfs([0] * len(emoticons), 0)
for d in range(len(sale)):
user_count = 0
profit = 0
for user in users:
buy_count = 0
for i in range(len(emoticons)):
if sale[d][i] >= user[0]:
buy_count += emoticons[i] * ((100 - sale[d][i]) / 100)
if user[1] <= buy_count:
user_count += 1
else:
profit += buy_count
if answer[0] < user_count:
answer = [user_count, int(profit)]
elif answer[0] == user_count:
if answer[1] < profit:
answer = [user_count, int(profit)]
return answer
'알고리즘' 카테고리의 다른 글
[알고리즘/파이썬] 백준 2252 - 줄 세우기 (1) | 2024.01.21 |
---|---|
[알고리즘/파이썬] 백준 17404 - RGB거리 2 (1) | 2024.01.21 |
[알고리즘/파이썬] 백준 9465 - 스티커 (0) | 2024.01.18 |
[알고리즘/파이썬] 백준 9251 - LCS (0) | 2024.01.18 |
[알고리즘/파이썬] 백준 5639 - 이진 검색 트리 (0) | 2024.01.16 |