-
Notifications
You must be signed in to change notification settings - Fork 14
/
algorithm_5.hpp
24 lines (18 loc) · 975 Bytes
/
algorithm_5.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "util.hpp"
//////////////////////////// TASK 5 ////////////////////////////
int naive_10_perc_of_not_bankrupted(std::vector<int>& d) {
std::sort(d.begin(), d.end());
auto it = std::lower_bound(d.begin(), d.end(), 0);
auto end_of_10_perc = it + static_cast<std::size_t>((d.end() - it) * 0.1);
return *end_of_10_perc;
}
int optimized_10_perc_of_not_bankrupted(std::vector<int>& d) {
// TASK: Improve
std::sort(d.begin(), d.end());
auto it = std::lower_bound(d.begin(), d.end(), 0);
auto end_of_10_perc = it + static_cast<std::size_t>((d.end() - it) * 0.1);
return *end_of_10_perc;
}
//////////////////////////// DETAIL ////////////////////////////
BENCH(algorithms, naive_10_perc_pos, naive_10_perc_of_not_bankrupted, naive_10_perc_of_not_bankrupted)->Range(8, 8 << 10)->Complexity();
BENCH(algorithms, optim_10_perc_pos, optimized_10_perc_of_not_bankrupted, naive_10_perc_of_not_bankrupted)->Range(8, 8 << 10)->Complexity();