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 |
Tags
- 1967번
- C++
- UnrealMP
- 데이터베이스 배움터
- 백준
- Security
- 오손데이터읽기
- 의미와 무의미의 경계에서
- OS
- 언리얼 커스텀 플러그인
- 1253번
- 1759번
- 실습
- 2단계로킹
- UActor
- 백준 1253번
- 셰그먼트트리
- SQL
- 언리얼 플러그인
- 민겸수
- objtofbx
- hackerank
- Unreal
- Linux
- 5639
- oracle
- FBX
- 트랜잭션 관리
- command not found
- 비재귀셰그먼트
Archives
- Today
- Total
fatalite
프로그래머스 이모티콘 할인행사 본문
순열 구현 방법 순간 헷갈려서 애먹은
그래도 천천히 생각하니깐 됐다
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;
vector<vector<int>> dupPermutations;
pair<int, int> Simulate(
vector<vector<int>> users,
vector<int> emoticons,
vector<int> discountPercents)
{
int emoticonPlus = 0;
int emoticonMoney = 0;
for(vector<int> user : users)
{
int userSum = 0;
for(int j = 0; j < emoticons.size(); j++)
{
if(user[0] <= discountPercents[j])
{
userSum += (double)(emoticons[j] * (1 - (double)discountPercents[j] / 100));
}
}
if(userSum >= user[1])
{
emoticonPlus += 1;
}
else
{
emoticonMoney += userSum;
}
}
return {emoticonPlus, emoticonMoney };
}
bool Compare(pair<int, int> p1, pair<int, int> p2)
{
if(p1.first == p2.first)
{
return p1.second > p2.second;
}
else
{
return p1.first > p2.first;
}
}
void DupPermutation(vector<int>& current, vector<int>& emoticons)
{
if(current.size() == emoticons.size())
{
dupPermutations.push_back(current);
return;
}
for(int i = 1 ; i <= 4; i++)
{
vector<int> next = current;
next.push_back(i * 10);
DupPermutation(next, emoticons);
}
}
vector<int> solution(vector<vector<int>> users, vector<int> emoticons) {
vector<pair<int,int>> simulationResults;
vector<int> tmp;
DupPermutation(tmp, emoticons);
for(vector<int> v : dupPermutations)
{
pair<int, int> p = Simulate(users, emoticons, v);
simulationResults.push_back(p);
}
sort(simulationResults.begin(), simulationResults.end(), Compare);
return {simulationResults[0].first, simulationResults[0].second };
}
'코딩 인터뷰 > C++' 카테고리의 다른 글
프로그래머스 점프와 순간이동 (0) | 2024.10.20 |
---|---|
프로그래머스 우박 수열 정적분 (0) | 2024.10.09 |
프로그래머스 단어 변환 (1) | 2024.10.06 |
프로그래머스 n진수 게임 (0) | 2024.10.01 |
프로그래머스 - 괄호 변환 (0) | 2024.09.29 |