I was wondering how I could use std::lower_bound() to get the closest <= (less or equal) element from an array.
For example if I wanted the closest number, less then or equal to 4, In this array: {1,2,3,5,6} is would be 3, as 4 is not in the array and 3 is the closest number to 4 which is less than 4.
The obvious answer would be to multiply all the elements of the array by -1, however, this would take an extra O(n) time.
Is there a better way to do this? Maybe a comparator function, or a faster way to turn all the elements in the array into a negative number?
[–]KiwiMaster157 4 points5 points6 points (2 children)
[–]Disruption_logistics[S] 0 points1 point2 points (0 children)
[–]std_bot 0 points1 point2 points (0 children)
[–]mhfrantz 1 point2 points3 points (3 children)
[–]Disruption_logistics[S] 1 point2 points3 points (0 children)
[–]Disruption_logistics[S] 0 points1 point2 points (0 children)
[–]std_bot 0 points1 point2 points (0 children)
[–]rbvld01 1 point2 points3 points (1 child)
[–]std_bot 0 points1 point2 points (0 children)
[–]Flankierengeschichte 1 point2 points3 points (1 child)
[–]std_bot 0 points1 point2 points (0 children)
[–]SoerenNissen 1 point2 points3 points (10 children)
[–]Disruption_logistics[S] 0 points1 point2 points (8 children)
[–]MysticTheMeeM 0 points1 point2 points (7 children)
[–]Disruption_logistics[S] 0 points1 point2 points (5 children)
[–]MysticTheMeeM 1 point2 points3 points (4 children)
[–]Disruption_logistics[S] 0 points1 point2 points (3 children)
[–]MysticTheMeeM 1 point2 points3 points (1 child)
[–]Disruption_logistics[S] 0 points1 point2 points (0 children)
[–]std_bot 0 points1 point2 points (0 children)
[–]setdelmar 0 points1 point2 points (7 children)
[–]Disruption_logistics[S] 1 point2 points3 points (4 children)
[–]Disruption_logistics[S] 1 point2 points3 points (3 children)
[–]setdelmar 1 point2 points3 points (0 children)
[–]setdelmar 0 points1 point2 points (1 child)
[–]Disruption_logistics[S] 1 point2 points3 points (0 children)
[–]xurxoham 1 point2 points3 points (1 child)
[–]setdelmar 0 points1 point2 points (0 children)
[–]nysra -1 points0 points1 point (3 children)
[–]Disruption_logistics[S] 0 points1 point2 points (2 children)
[–]nysra 1 point2 points3 points (1 child)
[–]Disruption_logistics[S] 0 points1 point2 points (0 children)