일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 서이추 자동
- 크롤러
- 웹소켓
- 셀레니움
- node.js
- 서로이웃추가 자동
- rabbitmq
- Java
- amqplib
- kwoss2341
- 국세청
- 서이추 매크로
- 실시간
- Selenium
- 네이버 블로그 이웃추가 자동
- Selenium 네이버 블로그
- 서로이웃추가 매크로
- 네이버 블로그
- 스크래퍼
- nodejs
- Node
- socket.io
- 크롤링
- 실시간 웹소켓 서버
- 웹소켓 서버
Archives
- Today
- Total
defaultK
[프로그래머스] (조합) 카카오 메뉴 리뉴얼 c++ 본문
https://programmers.co.kr/learn/courses/30/lessons/72411
코딩테스트 연습 - 메뉴 리뉴얼
레스토랑을 운영하던 스카피는 코로나19로 인한 불경기를 극복하고자 메뉴를 새로 구성하려고 고민하고 있습니다. 기존에는 단품으로만 제공하던 메뉴를 조합해서 코스요리 형태로 재구성해서
programmers.co.kr
기본적인 아이디어
1. 요리가 2번이상 나온 요리들의 집합(n개)을 구한다.
2. n개의 요리들중 k개를 뽑는 모든 조합의 경우의수 nCk 을 구한다. ( k= course수)
3. nCk 각각의 경우의 수 마다 해당 경우의수 요리를 모두 주문한 손님의 수를 구한다.
4. 손님수의 최댓값의 메뉴구성을 answer.push_back() 해준다.
5. answer 벡터 sort
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
bool cmp(vector <int> a, vector <int> b)
{
return a[0]>b[0];
}
//https://programmers.co.kr/learn/courses/30/lessons/72411
vector<string> solution(vector<string> orders, vector<int> course) {
vector<string> answer;
int n=orders.size();
string s="";
int food[n][26];
int total[26];
for(int i=0; i<26; i++)
{
total[i]=0;
}
for(int i=0; i<n; i++)
{
for(int j=0; j<26; j++)
{
food[i][j]=0;
}
}
for(int i=0; i<n; i++)
{
for(int j=0; j<orders[i].length(); j++)
{
food[i][orders[i][j]-'A']++;
total[orders[i][j]-'A']++;
}
}
for(int i=0; i<26; i++)
{
if(total[i]>1)
{
s+=(char)(i+'A');
}
}
for(int go=0; go<course.size(); go++)
{
int cnt=course[go];
vector <int> mycom;
if(cnt>s.length()) continue;
for(int i=0; i<s.length(); i++)
{
if(i<cnt)
{
mycom.push_back(1);
}
else
{
mycom.push_back(0);
}
}
sort(mycom.begin(), mycom.end());
vector < vector <int> > mycnt;
vector < vector <int> > mys;
do
{
vector<int> t;
for(int i=0; i<mycom.size(); i++)
{
if(mycom[i] == 1)
{
t.push_back(i);
}
}
mys.push_back(t);
}while(next_permutation(mycom.begin(), mycom.end()));
for(int i=0; i<mys.size(); i++)
{
int m=0;
vector <int> k;
for(int j=0; j<n; j++)
{
int sw=0;
for(int k=0; k<cnt; k++)
{
if(food[j][s[mys[i][k]]-'A']==0)
{
sw=1;
break;
}
}
if(sw==0) m++;
}
if(m>1)
{
k.push_back(m);
k.push_back(i);
mycnt.push_back(k);
}
}
sort(mycnt.begin(),mycnt.end(),cmp);
if(mycnt.size()==0||mycnt[0][0]<2) continue;
int maxmm=mycnt[0][0];
for(int i=0; i<mycnt.size(); i++)
{
string str="";
if(maxmm==mycnt[i][0])
{
for(int j=0; j<cnt; j++)
{
str+=s[mys[mycnt[i][1]][j]];
}
answer.push_back(str);
}
else
{
break;
}
}
}
sort(answer.begin(),answer.end());
return answer;
}
'알고리즘 ( C++ ) > 프로그래머스' 카테고리의 다른 글
[프로그래머스] 카카오 광고 삽입 c++ (0) | 2021.02.08 |
---|---|
[프로그래머스] (다익스트라) 카카오 합승 택시 요금 c++ (0) | 2021.02.05 |
[프로그래머스] (그리디) 큰 수 만들기 c++ (0) | 2021.01.31 |
[프로그래머스] (최소히프) 더 맵게 c++ (0) | 2021.01.30 |
[프로그래머스] 카카오 캠핑 c++ (0) | 2021.01.27 |
Comments