C++ make_heap,push_heap,pop_heap,sort_heap(以最大的K个数为例)
来源:互联网 发布:大数据怎么算平均年龄 编辑:程序博客网 时间:2024/06/17 02:27
找出最大的20个数
#include <iostream>#include <algorithm>#include <numeric>#include <string>#include <array>#include <vector>#include <functional>#include <hash_set>#include <ctime>using namespace std;int main(){//freopen("C:\\in.txt","r",stdin);vector<int> t(50);iota(t.begin(),t.end(),1);random_shuffle(t.begin(),t.end());for_each(t.begin(),t.end(),[](int i){cout<<i<<endl;});cout<<endl;make_heap(t.begin(),t.begin()+21,greater<int>());for(auto it=t.begin()+21;it!=t.end();){push_heap(t.begin(),t.begin()+21,greater<int>());pop_heap(t.begin(),t.begin()+21,greater<int>());it=t.erase(t.begin()+20);}sort(t.begin(),t.end(),greater<int>());for_each(t.begin(),t.end(),[](int i){cout<<i<<endl;});return 0;}
0 0
- C++ make_heap,push_heap,pop_heap,sort_heap(以最大的K个数为例)
- C++中堆的应用:make_heap, pop_heap, push_heap, sort_heap, priority_queue
- C++中堆的应用:make_heap, pop_heap, push_heap, sort_heap
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap。
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap。
- STL---heap概述,make_heap,sort_heap,pop_heap,push_heap
- c++ make_heap, pop_heap, push_heap, sort_heap详解
- make_heap, push_heap, pop_heap, 的使用
- 【STL】Heap算法——push_heap、pop_heap、sort_heap、make_heap
- make_heap(), pop_heap(), push_heap()用法
- make_heap(), pop_heap(), push_heap()用法
- priority_queue 调用 STL里面的 make_heap(), pop_heap(), push_heap() 算法
- STL中heap相关函数的用法:make_heap,push_heap,pop_heap...
- sort_heap后使用push_heap ,pop_heap异常
- STL中的make_heap、push_heap、pop_heap示例程序
- 【优先队列】【堆】STL之priority_queue、make_heap()、push_heap()、pop_heap()、容器适配器
- Java集群之session共享解决方案
- Word Search
- LeetCode(75)Sort Colors (荷兰三色旗问题 Dutch National Flag)
- [LeetCode] - Word Break
- [LeetCode] - Word Break II
- C++ make_heap,push_heap,pop_heap,sort_heap(以最大的K个数为例)
- Word Ladder
- Vim插件YouCompleteMe翻译之 README.md(Part I)
- 嵌入式环境搭建之samba
- Ubuntu下搭建嵌入式环境
- 《Programming Interviews Exposed》 中的一道递归题:Telephone number to words
- 分片(Sharding)的全局ID生成
- LeetCode - Pow
- 排序算法粗略总结