最佳答案
假设你有一架飞机,燃料不足。除非这架飞机的乘客重量减轻3000磅,否则它将无法抵达下一个机场。为了挽救最多的生命,我们想先把最重的人扔出飞机。
哦,是的,飞机上有数百万人,我们想要一个最优算法来找出最重的乘客,而不必对整个列表进行排序。
这是我试图用c++编写代码的代理问题。我想按重量对旅客舱单进行“部分排序”,但我不知道需要多少元素。我可以实现我自己的“partial_sort”算法(“partial_sort_accumulate_until”),但我想知道是否有任何更简单的方法来使用标准的STL来做到这一点。