HDOJ 1509 Windows Message Queue(优先队列)
来源:互联网 发布:蓄水池抽样算法 编辑:程序博客网 时间:2024/05/16 13:45
Windows Message Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4380 Accepted Submission(s): 1735
Problem Description
Message queue is the basic fundamental of windows system. For each process, the system maintains a message queue. If something happens to this process, such as mouse click, text change, the system will add a message to the queue. Meanwhile, the process will do a loop for getting message from the queue according to the priority value if it is not empty. Note that the less priority value means the higher priority. In this problem, you are asked to simulate the message queue for putting messages to and getting message from the message queue.
Input
There's only one test case in the input. Each line is a command, "GET" or "PUT", which means getting message or putting message. If the command is "PUT", there're one string means the message name and two integer means the parameter and priority followed by. There will be at most 60000 command. Note that one message can appear twice or more and if two messages have the same priority, the one comes first will be processed first.(i.e., FIFO for the same priority.) Process to the end-of-file.
Output
For each "GET" command, output the command getting from the message queue with the name and parameter in one line. If there's no message in the queue, output "EMPTY QUEUE!". There's no output for "PUT" command.
Sample Input
GETPUT msg1 10 5PUT msg2 10 4GETGETGET
Sample Output
EMPTY QUEUE!msg2 10msg1 10EMPTY QUEUE!
优先队列二级排序,和排队看病题很像,模板题。
代码如下:
#include<cstdio>#include<queue>#include<cstring>using namespace std;struct node{char meg[20];int num,pri,id;}s;bool operator < (const node &x,const node &y){if(x.pri==y.pri) return x.id>y.id;else return x.pri>y.pri;//注意:题中给出的是优先级值越小,优先级越大 }int main(){int n,a,b,c=1;char st[5],str[20];priority_queue<node>q;while(scanf("%s",st)!=EOF){if(strcmp(st,"PUT")==0){scanf("%s%d%d",str,&a,&b);strcpy(s.meg,str);s.num=a;s.pri=b;s.id=c++;q.push(s);}else{if(!q.empty()){s=q.top();q.pop();printf("%s %d\n",s.meg,s.num);}else printf("EMPTY QUEUE!\n");}}return 0;}
0 0
- hdoj 1509 Windows Message Queue 优先队列
- hdoj 1509 Windows Message Queue(优先队列)
- HDOJ 1509 Windows Message Queue(优先队列)
- Hdoj 1509 -Windows Message Queue 优先队列最小堆实现
- HDOJ 1509 Windows Message Queue (优先队列)
- hdoj 1509 Windows Message Queue 【STL 优先队列】
- HDOJ 1509 Windows Message Queue (简单优先队列 )
- hdoj 1509 Windows Message Queue [STL 优先队列]
- HDOJ 1509 Windows Message Queue(优先队列)
- hdu 1509 Windows Message Queue 优先队列
- hdu 1509 Windows Message Queue(优先队列)
- HDU-1509-Windows Message Queue(优先队列)
- HDU 1509 Windows Message Queue 【优先队列】
- hdu-1509 Windows Message Queue(优先队列)
- HDU 1509:Windows Message Queue【优先队列】
- HDU 1509 Windows Message Queue(优先队列)
- HDUoj 1509 Windows Message Queue ( 优先队列
- ZOJ 2724/HDU 1509 Windows Message Queue(优先队列)
- hadoop 在win系统中的eclipse开发测试问题及解决
- caffe study - 数据结构(1)
- eclipse 插件开发
- [LeetCode][Java] Word Ladder II
- The first~
- HDOJ 1509 Windows Message Queue(优先队列)
- Android事件传递
- 程序员面试的奇葩问题
- ehCache 2
- unique函数去除重复元素在vector中的应用
- Win7/win8 系统下 Firefox hostadmin插件无法修改Host
- 【翻译】D3D10/D3D11中的纹理资源
- 多校3
- KMP算法小结