31796 c++ - 한빛미디어 (Easy)
2024. 11. 27. 16:13ㆍ🐣/BOJ
기본적인 그리디문제
[Swift 이코테] Greedy / 그리디 / 탐욕 알고리즘
그리디 알고리즘이란? Greedy algorithm은 최적해를 구하는 데에 사용되는 근사적인 방법으로, 여러 경우 중 하나를 결정해야 할 때마다 그 순간에 최적이라고 생각되는 것을 선택해 나가는 방식으
chanhhh.tistory.com
정렬을 사용해서 풀었다.
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int n;
int main() {
cin >> n;
vector<int> books(n);
for (int i = 0; i < n; i++) {
cin >> books[i];
}
sort(books.begin(), books.end());
int minB = 0, count = 0;
for (auto &b : books) {
if (minB * 2 <= b) {
minB = b;
count++;
}
}
cout << count;
return 0;
}
'🐣 > BOJ' 카테고리의 다른 글
21608 c++ - 상어 초등학교 (0) | 2024.11.26 |
---|---|
30049 c++ - 영업의 신 (0) | 2024.11.24 |
20920 c++ - 영단어 암기는 괴로워 (0) | 2024.11.23 |
6987 c++ - 월드컵 (0) | 2024.11.20 |
10827 c++ - a^b (0) | 2024.11.17 |