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 |
Tags
- --watch
- draganddrop
- MySQL
- css framework
- server
- mongoDB
- SDK upgrade
- react
- spread 연산자
- critical rendering path
- screencapture
- Google Developer API
- rpg server
- linux
- Camera Zoom
- Packet Network
- Google Refund
- springboot
- unity
- Unity IAP
- Unity Editor
- Spring Boot
- docker
- Digital Ocean
- java
- OverTheWire
- express
- nodejs
- Git
- Camera Movement
Archives
- Today
- Total
우당탕탕 개발일지
[프로그래머스] Level 2 . 이모티콘 할인행사 본문
https://school.programmers.co.kr/learn/courses/30/lessons/150368
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
1. 10%,20%,30%,40% 중 하나를 고르는 7개의 조합을 모두 찾는다.
2. 이 모든 조합들에 대해 총판매액과 플러스가입유저를 찾는다.
3. 플러스가입 유저가 제일많으면서 총 판매액이 가장 높은 경우를 리턴한다.
#include <string>
#include <vector>
using namespace std;
vector<int> answer(2,0);
vector<int> rateList = {10,20,30,40};
vector<vector<int>> rateCombinations;
void getCombinations(vector<int>& emo, int n){
if(emo.size() == n){
rateCombinations.push_back(emo);
return;
}
for(int rate : rateList){
emo.push_back(rate);
getCombinations(emo,n);
emo.pop_back();
}
}
void refreshAnswer(const vector<vector<int>>& users, const vector<int>& emoticons, vector<int> rates){
vector<int> prices(emoticons.size(),0);
for(int i=0; i<emoticons.size(); i++){
prices[i] = emoticons[i] * (100-rates[i]) /100;
}
int revenue = 0;
int plusUser = 0;
for(int i=0; i<users.size(); i++){
int totalPrice =0;
for(int j=0; j<emoticons.size(); j++){
if(users[i][0] <= rates[j]) totalPrice += prices[j];
}
if(totalPrice >= users[i][1]) plusUser++; // 플러스가입. 매출x
else revenue += totalPrice;
}
if(answer[0]<plusUser || (answer[0]==plusUser && answer[1]<revenue)){
answer[0] = plusUser;
answer[1] = revenue;
}
}
vector<int> solution(vector<vector<int>> users, vector<int> emoticons) {
vector<int> emo;
getCombinations(emo,emoticons.size());
for(auto combi : rateCombinations){
refreshAnswer(users,emoticons, combi);
}
return answer;
}
'Algorithm(c++) > Level 2' 카테고리의 다른 글
[프로그래머스] Level 2. 혼자 놀기의 달인 (1) | 2025.03.21 |
---|---|
[프로그래머스] Level 2. 숫자 블록 (0) | 2025.03.20 |
[프로그래머스] Level 2. 후보키 (1) | 2025.03.15 |
[프로그래머스] Level 2. 거리두기 확인하기 (0) | 2025.03.07 |
[프로그래머스] Level 2. 2개 이하로 다른 비트 (0) | 2025.02.26 |