STL模板库优先队列
来源:互联网 发布:python编写的小程序 编辑:程序博客网 时间:2024/06/06 07:13
#include<stdio.h>#include<stdlib.h>#include<queue>#include<algorithm>using namespace std;priority_queue<int>q;int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { int val; scanf("%d",&val); q.push(val); } while(!q.empty()) { int t=q.top();//返回优先队列中队顶的数据(优先级越高越先出) printf("t = %d\n",t); q.pop(); } return 0;}结构体优先队列#include<stdio.h>#include<stdlib.h>#include<queue>#include<algorithm>using namespace std;struct node{ int a,b; bool operator<(const node &s)const { if(a==s.a) return b<s.b;//最大值优先 else return a>s.a;//最小值优先 }};priority_queue<node> q;int main(){ int n; scanf("%d",&n); for(int i=0;i<n;i++) { struct node s; scanf("%d %d",&s.a,&s.b); q.push(s); } while(!q.empty()) { struct node t=q.top();//输出队顶 的数据(优先级越高,越先输出) printf("t.a = %d t.b = %d\n",t.a,t.b); q.pop(); } return 0;}
0 0
- STL模板库优先队列
- 优先队列stl 模板
- STL库---优先队列
- 标准模板库STL中优先队列Priority Queues使用手册
- STL模板库队列
- 【c++——STL】标准模板库STL中优先队列Priority Queues使用手册
- ACM 模板 c++ STL 队列 queue 优先队列
- C++STL中的标准模板——优先队列
- STL库之优先队列(例hdu1873)
- stl中的优先队列
- stl 优先队列
- STL 优先队列
- STL之优先队列
- STL priority_queue 优先队列
- STL-->优先队列
- STL之优先队列
- STL priority_queue 优先队列
- STL优先队列使用
- Android中View的滑动方式
- STL模板库栈
- Java关键字
- 数据结构C语言描述——用单链表实现多项式的相加
- MYSQL之插入更新删除数据
- STL模板库优先队列
- hdoj2187悼念512汶川大地震遇难同胞——老人是真饿了(sort+结构体+贪心)
- 光伏最大功率跟踪以及并网PSCAD模型
- HDU多校联合训练 Problem1001 Abandoned country
- 常用adb命令详解
- Git的使用
- 今年暑假不AC<hdoj2307>
- java序列化
- C++排序算法总结