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 | 31 |
Tags
- amba
- vitis
- axi
- SQL
- linux
- Bus
- verilog HDL
- Beakjoon
- 정보처리기사
- 정처기
- chip2chip
- 코딩테스트
- C++
- HDLBits
- baekjoon
- 자격증
- Zynq
- 실기
- UNIX
- boj
- verilog
- 리눅스
- AMBA BUS
- Vivado
- java
- FPGA
- Xilinx
- hdl
- Backjoon
- 백준
Archives
- Today
- Total
Hueestory
[2019 KAKAO BLIND] - 실패율 (C++) 본문
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
bool cmp(pair<double, int> &a, pair<double, int> &b) {
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
}
vector<int> solution(int N, vector<int> stages) {
vector<int> answer(N);
vector<pair<double, int>> rate;
for (int i = 1; i <= N; i++) {
double reach = 0, fail = 0;
for (int j = 0; j < stages.size(); j++) {
if (i <= stages[j])
reach++;
if (i == stages[j])
fail++;
}
if (reach != 0)
rate.push_back(make_pair(fail / reach, i));
else if (reach == 0)
rate.push_back(make_pair(0, i));
}
sort(rate.begin(), rate.end(), cmp);
for (int i = 0; i < N; i++) {
answer[i] = rate[i].second;
}
return answer;
}

'PS > programmers' 카테고리의 다른 글
| 정수를 나선형으로 배치하기 (Python) (0) | 2025.06.18 |
|---|---|
| [2019 KAKAO BLIND] - 오픈채팅방 (C++) (1) | 2024.08.28 |
| [2022 KAKAO BLIND] - 주차 요금 계산 (C++) (0) | 2024.08.28 |
| [2021 KAKAO BLIND] - 신규 아이디 추천 (C++) (0) | 2024.08.27 |
| [2022 KAKAO BLIND] - k진수에서 소수 개수 구하기 (C++) (0) | 2024.08.27 |
Comments