forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path3.cpp
More file actions
39 lines (31 loc) Β· 1.06 KB
/
3.cpp
File metadata and controls
39 lines (31 loc) Β· 1.06 KB
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
32
33
34
35
36
37
38
39
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, double> a, pair<int, double> b) {
if (a.second == b.second) return a.first < b.first;
return a.second > b.second;
}
vector<int> solution(int N, vector<int> stages) {
vector<pair<int, double> > v;
vector<int> answer;
int length = stages.size();
// μ€ν
μ΄μ§ λ²νΈλ₯Ό 1λΆν° NκΉμ§ μ¦κ°μν€λ©°
for (int i = 1; i <= N; i++) {
// ν΄λΉ μ€ν
μ΄μ§μ λ¨Έλ¬Όλ¬ μλ μ¬λμ μ κ³μ°
int cnt = count(stages.begin(), stages.end(), i);
// μ€ν¨μ¨ κ³μ°
double fail = 0;
if (length >= 1) {
fail = (double) cnt / length;
}
// 리μ€νΈμ (μ€ν
μ΄μ§ λ²νΈ, μ€ν¨μ¨) μμ μ½μ
v.push_back({i, fail});
length -= cnt;
}
// μ€ν¨μ¨μ κΈ°μ€μΌλ‘ κ° μ€ν
μ΄μ§λ₯Ό λ΄λ¦Όμ°¨μ μ λ ¬
sort(v.begin(), v.end(), compare);
// μ λ ¬λ μ€ν
μ΄μ§ λ²νΈ λ°ν
for (int i = 0; i < N; i++) {
answer.push_back(v[i].first);
}
return answer;
}