Windows Message Queue(优先队列)
Windows Message QueueTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) 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
GET PUT msg1 10 5 PUT msg2 10 4 GET GET GET
Sample Output
EMPTY QUEUE! msg2 10 msg1 10 EMPTY QUEUE!
|
题解:优先队列,要考虑同一优先级时的出列顺序;由于优先队列当优先级相同时随机输出队列,所以加一个z;否则wa;
代码:
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
const int MAXN=;
struct Node{
char ms[];
int x,y,z;
friend bool operator < (Node a,Node b){
if(a.y!=b.y)return a.y > b.y;
else return a.z>b.z;
}
};
Node people;
int main(){int k=;
char temp[];priority_queue<Node>message;
while(memset(temp,,sizeof(temp)),scanf("%s",temp)!=EOF){
if(!strcmp(temp,"GET")){
if(message.empty())puts("EMPTY QUEUE!");
else printf("%s %d\n",message.top().ms,message.top().x),message.pop();
}
else if(!strcmp(temp,"PUT"))k++,scanf("%s %d %d",people.ms,&people.x,&people.y),people.z=k,message.push(people);
}
return ;
}
Windows Message Queue(优先队列)的更多相关文章
- hdu 1509 Windows Message Queue (优先队列)
Windows Message QueueTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- zoj 2724 Windows Message Queue 优先队列
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724 题目大意: 给出两种操作,GET要求取出当前队首的元素,而PUT会输入名 ...
- hdoj 1509 Windows Message Queue【优先队列】
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- Windows Message Queue
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...
- zoj 2724 Windows Message Queue
Windows Message Queue Time Limit: 2 Seconds Memory Limit: 65536 KB Message queue is the basic f ...
- hdu1509(Windows Message Queue) 优先队列
点击打开链接 Problem Description Message queue is the basic fundamental of windows system. For each proces ...
- HDU 1509 Windows Message Queue(队列)
题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...
- D - Windows Message Queue
来源hdu1509 Message queue is the basic fundamental of windows system. For each process, the system mai ...
随机推荐
- php字符串标点等字符截取不乱吗 封装方法
方法一: /** +---------------------------------------------------------- * 功能:字符串截取指定长度 * leo.li hen ...
- NET中级课--文件,流,序列化2
1.流的类型体系: 基础流 装饰器流 包装器类 帮助类 2. stream file~ memory~ network~ stream是个 ...
- VS2012 拆分视图按钮不见,代码,设计
工具--选项--HTML设计器 然后重启就有了.
- Entity Framework数据库迁移
1.启用数据迁移: enable-Migrations2.增加一条数据库迁移指令:add-Migrations 必须带上一个版本名称,比如AddUsernamePassword完整的指令:add-Mi ...
- 上拉、下拉UITableView,交互式 模态弹出(自定义弹出动画)
部分代码 InteractiveTransition 类继承NSObject: - (instancetype)initWithPresentingController:(UITableViewCon ...
- 值栈和OGNL 之 7.1 值栈
7.1 值栈 7.1.1 值栈是什么 简单的说:值栈是对应每一个请求对象的轻量级的内存数据中心. Struts2中一个很激动人心的特性就是引入了值栈,在这里统一管理着数据,供Action.Resu ...
- (转)创建和查看Javadoc文档
原地址:http://jinnaxu-tju-edu-cn.iteye.com/blog/667177 Javadoc是Sun公司提供的一个技术,它从程序源代码中抽取类.方法.成员等注释形成一个和源代 ...
- (原)ubuntu16中简单的使用google的protobuf
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5804395.html 参考网址: http://www.cnblogs.com/luosongchao ...
- contentProvider内容提供者
contentProvider内容提供者 15. 四 / android基础 / 没有评论 步骤 权限在application中注册 Source code <provider an ...
- py正则表达式
1.元字符 . ^ $ * + ? {} [] \ | () --> [] : - 常用来指定一个字符集:[abc], [a-z] 匹配任意一个字符 - 元字符在字符集中不起作用:[akm ...