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. Monkey压力测试Android常见的错误类型及黑白名单的使用方法

    Android常见的错误类型有两种 1.ANR类型 1)在5秒内没有响应输入的事件(例如,按键按下,屏幕触摸) 2)BroadcastReceiver在10秒内没有执行完毕 2.Crash类型 1)异 ...

  2. HDU 3368 Reversi (暴力,DFS)

    题意:给定一个8*8的棋盘,然后要懂黑白棋,现在是黑棋走了,问你放一个黑子,最多能翻白子多少个. 析:我是这么想的,反正才是8*8的棋盘,那么就暴吧,反正不会超时,把每一个格能暴力的都暴力,无非是上, ...

  3. 设计模式09: Decorator 装饰模式(结构型模式)

    Decorator 装饰模式(结构型模式) 子类复子类,子类何其多加入我们需要为游戏中开发一种坦克,除了不同型号的坦克外,我们还希望在不同场合中为其增加以下一种多种功能:比如红外线夜视功能,比如水路两 ...

  4. Long-Polling, Websockets, SSE(Server-Sent Event), WebRTC 之间的区别与使用

    1.首先看下最简单的SSE: 只用支持SSE的浏览器(大部分)即可,浏览器内置EventSource对象,该对象默认隔三秒刷新一下response的数据. HTML代码(取自w3cschool): & ...

  5. Go语言最佳实践——面向对象

    对于接口,应使用组合而非继承的方式扩展: 对于结构体,应定义独立的结构体,而非用嵌套模拟继承. 值接收者和指针接收者: 1.对于不可变类型创建只接受值接收者的方法,而为可变的类型创建接受指针接收者的方 ...

  6. c#帮助类:发送邮件

    private static string IsOpenSendMail = ConfigurationManager.AppSettings["IsOpenSendMail"]; ...

  7. 【C#】LINQ

    一.什么是LINQ 长期以来,开发社区形成以下的格局: 1.面向对象与数据访问两个领域长期分裂,各自为政. 2.编程语言中的数据类型与数据库中的数据类型形成两套不同的体系,例如: C#中字符串用str ...

  8. owinAuthorize

    Nuget包获取 Install-Package Microsoft.AspNet.WebApi.Owin -Version 5.1.2 Install-Package Microsoft.Owin. ...

  9. Hexo基本使用

    1. 简述 Hexo是一个基于Node.js的博客系统,常用于搭建在GitHub上. 其本质其实是一个基于Node.js的内嵌webserver的程序,可以通过一些命令根据markdown生成静态页面 ...

  10. react-native自定义原生组件

    此文已由作者王翔授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 使用react-native的时候能够看到不少函数调用式的组件,像LinkIOS用来呼起url请求  Link ...