https://www.welcomekakao.com/learn/courses/30/lessons/42889
코딩테스트 연습 - 실패율
실패율 슈퍼 게임 개발자 오렐리는 큰 고민에 빠졌다. 그녀가 만든 프랜즈 오천성이 대성공을 거뒀지만, 요즘 신규 사용자의 수가 급감한 것이다. 원인은 신규 사용자와 기존 사용자 사이에 스��
www.welcomekakao.com
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int schk[200001];
vector <pair<double,int>> nlist;
bool cmp(pair<double,int> a,pair<double,int> b)
{
if(a.first != b.first) return a.first > b.first;
else return a.second < b.second;
}
vector<int> solution(int N, vector<int> stages) {
vector<int> answer;
for(int i=0;i<stages.size();i++){
int chk = stages[i];
schk[chk]++;
}
int cnt=stages.size();
for(int i=1;i<=N;i++){
if(cnt!=0){
double k = 1.0*schk[i]/cnt;
nlist.push_back({k,i});
cnt-=schk[i];
cout<<k<<" ";
}else{
nlist.push_back({0,i});
}
}
sort(nlist.begin(),nlist.end(),cmp);
for(int i=0;i<nlist.size();i++){
answer.push_back(nlist[i].second);
}
return answer;
}
'개발자 > algorithm' 카테고리의 다른 글
백준 2618번 : 경찰차 (c++) (0) | 2020.08.28 |
---|---|
백준 18227번 : 성대나라의 물탱크 (c++) (0) | 2020.08.28 |
2020 카카오 코딩테스트 3번 : 자물쇠와 열쇠 (c++) (0) | 2020.08.25 |
2020 카카오 코딩테스트 1번 : 문자열 압축 (c++) (0) | 2020.08.24 |
백준 1102번 : 발전소 (c++) (0) | 2020.08.21 |