hdu 1059 优先级队列
来源:互联网 发布:艺术字设计软件下载 编辑:程序博客网 时间:2024/04/30 11:41
裸的优先级队列,参考了一下他人的代码
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509
原帖地址:http://yomean.blog.163.com/blog/static/189420225201110811454386/?COLLCC=2615871725&COLLCC=2615871724&
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>#include <algorithm>#include <cmath>#include<queue>using namespace std;struct mes{ int pri,no,val;//no为mes进入先后编号顺序 char name[20]; bool operator <(const mes t)const { if(pri==t.pri) return no > t.no; else return pri > t.pri; //从小到大,小的优先级最高 }};priority_queue<mes>Q;/*也可以这样定义,那个帖子的作者就是这样用的struct cmp//用结构体作为比较函数{ bool operator ()(mes a,mes b) { if (a.pri != b.pri) return a.pri > b.pri;//这里如果是大于,则得出来的队列是从小到大 else return a.o > b.o;//同上述 }};priority_queue<mes,vector<mes>,cmp> Q;*/int main(){ freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); char order[20]; mes a; int k=0;//记录编号 while(!Q.empty()) Q.pop(); while(cin>>order) { if(strcmp(order,"PUT")==0) { cin>>a.name>>a.val>>a.pri; k++; a.no=k; Q.push(a); } else { if(Q.empty()) cout<<"EMPTY QUEUE!"<<endl; else { cout<<Q.top().name<<" "<<Q.top().val<<endl; Q.pop(); } } } return 0;}
- hdu 1059 优先级队列
- hdu 1873 优先级队列
- hdu 1896 优先级队列
- hdu 4006 优先级队列
- HDU-1026-优先级队列
- hdu 1053 哈夫曼树 优先级队列
- hdu 1242 优先级队列 bfs
- hdu 1026 bfs+优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 优先级队列
- 两个大牛的研究方向(2)
- Oracle 10g数据库迁移的经验 Windows环境
- 真机调试Error launching remote program: failed to get the task for process xxx.
- 利用VTS与bacnet协议栈进行通信---ReadProperty
- windows-IOCP模型总结
- hdu 1059 优先级队列
- IBM实习生笔试题目(6)
- fiddler替换服务器上文件进行本地调试
- 透彻理解异常并合理使用异常
- liux文件的每行末尾^M$ 和$
- H264 video RTP payload and SDP
- C++ 虚函数表解析
- 进程与线程区别
- HBase性能优化方法总结(一):表的设计