Windows Message Queue
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9202    Accepted Submission(s): 3836
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!

C/C++:

 #include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0x3f3f3f3f
using namespace std;
const int MAX = ; char buf[MAX];
int id = ; struct node
{
char name[MAX];
int n, val, id;
friend bool operator < (node a, node b)
{
if (a.val != b.val)
return a.val > b.val;
return a.id > b.id;
}
}; int main()
{
priority_queue <node> Q;
while (~scanf("%s", &buf))
{
if (strcmp(buf, "GET") == )
{
if (Q.empty()) printf("EMPTY QUEUE!\n");
else
{
printf("%s %d\n", Q.top().name, Q.top().n);
Q.pop();
}
}
else
{
node temp;
temp.id = id ++;
scanf("%s %d %d", &temp.name, &temp.n, &temp.val);
Q.push(temp);
}
}
}

hdu 1509 Windows Message Queue (优先队列)的更多相关文章

  1. hdu 1509 Windows Message Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...

  2. HDU 1509 Windows Message Queue(队列)

    题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...

  3. hdu 1509 Windows Message Queue (优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...

  4. hdoj 1509 Windows Message Queue【优先队列】

    Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  5. zoj 2724 Windows Message Queue 优先队列

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724 题目大意: 给出两种操作,GET要求取出当前队首的元素,而PUT会输入名 ...

  6. Windows Message Queue(优先队列)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  7. Windows Message Queue

    Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  8. zoj 2724 Windows Message Queue

    Windows Message Queue Time Limit: 2 Seconds      Memory Limit: 65536 KB Message queue is the basic f ...

  9. hdu1509(Windows Message Queue) 优先队列

    点击打开链接 Problem Description Message queue is the basic fundamental of windows system. For each proces ...

随机推荐

  1. Neo4j:图数据库GraphDB(四)Python中的操作

    本文总结下Python中如何操作Neo4j数据库,用到py2neo包,Pip install 一下. 1 连接neo4j数据库:跟其它数据库一样,操作前必须输入用户名和密码及地址连接一下. from ...

  2. freertos学习

    freertos的基本框架如下 注意有三点很重要: 1.任务的资源 (1)任务优先级:freertos 能够调度的任务优先级在freertosConfig.h中的configMAX_PRIORITIE ...

  3. SpringBoot-Mysql模板多数据源加载

    SpringBoot-Mysql模板多数据源加载 qq交流群: 812321371 微信交流群: MercyYao 简介 在 java 项目里常用到 mysql 多数据源操作.结合 springboo ...

  4. JVM学习记录1--JVM内存布局

    先上个图 这是根据<Java虚拟机规范(第二版)>所画的jvm内存模型. 程序计数器:程序计数器是用来记录当前线程方法执行顺序的,对应的就是我们编程中一行行代码的执行顺序,如分支,跳转,循 ...

  5. MyEclipse 2013配置JDBC连接mySQL||Tomcat 7.0 8.0 配置 JDBC |配置mysql-connector-java-5.1.16

    MyEclipse->Preferences->MyEclipse->Severs->Intergated Sandbox->Myeclipse Tomcat 7(或者T ...

  6. OptimalSolution(6)--栈和队列

    一.设计一个有getMin功能的栈 题目:实现一个特殊的栈,在实现栈的基本功能的基础上,再实现返回栈中最小元素的操作.pop.push.getMin操作的时间复杂度都是O(1). 思路:设计两个栈,一 ...

  7. MySQL基础篇(3)常用函数和运算符

    一.字符串函数(索引位置都从1开始) CONCAT(S1,S2,...Sn): 连接S1,S2,...Sn为一个字符串,任何字符串与NULL进行连接的结果都是NULL INSERT(str,x,y,i ...

  8. Mysql数据库(九)备份与恢复

    一.数据备份 1.使用mysqldmp命令备份 (1)备份一个数据库 mysqldump -u root -p dbname table1 table2 ... > D:\BackName.sq ...

  9. Flink 从 0 到 1 学习 —— Flink Data transformation(转换)

    toc: true title: Flink 从 0 到 1 学习 -- Flink Data transformation(转换) date: 2018-11-04 tags: Flink 大数据 ...

  10. 关于ArcGIS的OBJECTID生成策略拙见

    目录 诉求SDEOBJECTIDArcMap编辑重置OBJECTID 诉求 非GIS专业的人员可能很难理解ArcSDE中的表OBJECTID的重要性,要么总想着自己动手去维护,要么就想直接忽略它,导致 ...