Windows Message Queue

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9171    Accepted Submission(s): 3821

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!
 
直接优先队列+结构。注意的是,同一消息可能出现多次,因此要对每条消息按出现顺序标记一下
 
 
#include<iostream>
#include<queue>
#include<string.h>
#include<stdio.h>
using namespace std;
struct node
{
char name[];
int num;//指令编号
int rank;//第一优先级
int val;//第二优先级(同一消息可能出现多次,因此需要按输入顺序重新编号)
}p;
bool operator <(const node &x,const node &y)//重载小于运算符
{
if(x.rank==y.rank)
return x.val>y.val;//第二优先级越大越小
else
return x.rank>y.rank;//越大优先级越小
}
int main()
{
char str[];
int k=;
priority_queue<node>q;
while(scanf("%s",str)!=EOF)
{
if(strcmp(str,"PUT")==)
{
scanf("%s %d %d",p.name,&p.num,&p.rank);
p.val=++k;
q.push(p);
}
else
{
if(q.empty())
printf("EMPTY QUEUE!\n");
else
{
p=q.top();
q.pop();
printf("%s %d\n",p.name,p.num);
}
}
}
return ;
}

hdu1509 优先队列的更多相关文章

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

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

  2. 堆排序与优先队列——算法导论(7)

    1. 预备知识 (1) 基本概念     如图,(二叉)堆是一个数组,它可以被看成一个近似的完全二叉树.树中的每一个结点对应数组中的一个元素.除了最底层外,该树是完全充满的,而且从左向右填充.堆的数组 ...

  3. 数据结构:优先队列 基于list实现(python版)

    #!/usr/bin/env python # -*- coding:utf-8 -*- #Author: Minion-Xu #list实现优先队列 class ListPriQueueValueE ...

  4. python优先队列,队列和栈

    打印列表的疑问 class Node: def __str__(self): return "haha" print([Node(),Node()]) print(Node()) ...

  5. 数据结构作业——Sanji(优先队列)

    山治的婚约 Description 我们知道,山治原来是地下有名的杀人家族文斯莫克家族的三子,目前山治的弟弟已经出现,叫做四治,大哥二哥就叫汪(One)治跟突(Two)治好了(跟本剧情无关) .山治知 ...

  6. Java优先队列

    按照Java api的说法: java.util.PriorityQueue.PriorityQueue() Creates a PriorityQueue with the default init ...

  7. 优先队列实现Huffman编码

    首先把所有的字符加入到优先队列,然后每次弹出两个结点,用这两个结点作为左右孩子,构造一个子树,子树的跟结点的权值为左右孩子的权值的和,然后将子树插入到优先队列,重复这个步骤,直到优先队列中只有一个结点 ...

  8. “玲珑杯”ACM比赛 Round #7 B -- Capture(并查集+优先队列)

    题意:初始时有个首都1,有n个操作 +V表示有一个新的城市连接到了V号城市 -V表示V号城市断开了连接,同时V的子城市也会断开连接 每次输出在每次操作后到首都1距离最远的城市编号,多个距离相同输出编号 ...

  9. Dijkstra算法优先队列实现与Bellman_Ford队列实现的理解

    /* Dijkstra算法用优先队列来实现,实现了每一条边最多遍历一次. 要知道,我们从队列头部找到的都是到 已经"建好树"的最短距离以及该节点编号, 并由该节点去更新 树根 到其 ...

随机推荐

  1. 浅谈Android内存管理

    最近在网上看了不少Android内存管理方面的博文,但是文章大多都是就单个方面去介绍内存管理,没有能全局把握,缺乏系统性阐述,而且有些观点有误,仅仅知道这些,还是无法从整体上理解内存管理,对培养系统优 ...

  2. App测试从入门到精通之性能测试

    好了,上节我们介绍了关于APP测试的功能测试方面一些细节.这一篇我们来介绍一下,关于APP测试过程中的性能测试参考要点,我们需要思考的如下: 响应时间 1.APP安装卸载的响应时间 2.APP各种功能 ...

  3. DataType--数值类型

    SQL Server数值类型可以分为精确数字类型和近似数字类型精确数字BIT/SMALLINT/TINYINT/INT/BIGINTNUMERIC/DECIMAL/SMALLMONEY/MONEY 近 ...

  4. C# 高斯消元项目运用

    C# 高斯消元项目运用 最近项目涉及到一个需求,需要把指定数量的多个商品,混合装入到多个不同型号的箱子中(每种型号的箱子装入商品的种类和个数是固定的).这就涉及到解多元一次方程 针对多元一次方程一般用 ...

  5. 远程连接linux服务上的mysql

    如果有童鞋linux上还未安装mysql数据库可以参考我上一篇博客 (1)首先确保 linux服务上的 mysql 的3306端口是对外开放的 编辑 vi /etc/sysconfig/iptable ...

  6. 十七、创建一个 WEB 服务器(一)

    1.Node.js 创建的第一个应用 var http=require("http") http.createServer(function (req,res) { res.wri ...

  7. mysql事务隔离级别回顾

    事务隔离级别是针对读数据库数据的一种规则.事务隔离级别是数据库属性不是事务属性. 1.读未提交(read uncommited) 可以读到其他事务修改未提交的数据.(有 脏读,不可重复读,幻读) 事务 ...

  8. Tensorflow报错:InvalidArgumentError: You must feed a value for placeholder tensor 'input_y' with dtype

    此错误神奇之处是每次第一次运行不会报错,第二次.第三次第四次....就都报错了.关掉重启,又不报错了,运行完再运行一次立马报错!搞笑! 折磨了我半天,终于被我给解决了! 问题解决来源于这边博客:htt ...

  9. 如何调用写好的指定模块?——sys.path

    python之sys模块详解 sys模块功能多,我们这里介绍一些比较实用的功能,相信你会喜欢的,和我一起走进python的模块吧! sys模块的常见函数列表 sys.argv: 实现从程序外部向程序传 ...

  10. Codeforces Round #546 (Div. 2)D(贪心,思维,SET,VECTOR,模拟)

    #include<bits/stdc++.h>using namespace std;int a[300007],b[500007],c[500007];set<int>st[ ...