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. WebDriverWait等设置等待时间和超时时间

    1.显示等待 等待页面加载完成,找到某个条件发生后再继续执行后续代码,如果超过设置时间检测不到则抛出异常 WebDriverWait(driver, timeout, poll_frequency=0 ...

  2. c++虚析构函数的使用及其注意点

    // ConsoleApplication33.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include <iostream& ...

  3. SpringMVC——拦截器

    Spring MVC也可以使用拦截器对请求进行拦截处理,用户可以自定义拦截器来实现特定的功能,自定义的拦截器必须实现HandlerInterceptor接口 preHandle():这个方法在业务处理 ...

  4. 深数据 - Deep Data

    暂无中文方面的信息,E文的也非常少,原文连接: A lot of great pieces have been written about the relatively recent surge in ...

  5. unity 大游戏使用什么框架

    关于Unity的架构有如下几种常用的方式.1.EmptyGO在Hierarchy上创建一个空的GameObject,然后挂上所有与GameObject无关的逻辑控制的脚本.使用GameObject.F ...

  6. 函数LEN()使用方法

    string pro_sql = string.Format("select pr_bianma from tb_products where pr_bianma like '%120201 ...

  7. linux学习之路(4)

    用户身份与文件权限 通过uid来区分:  管理员 UID 为 0:系统的管理员用户. 系统用户 UID 为 1-999: Linux 系统为了避免因某个服务程序出现漏洞而被黑客提 权至整台服务器,默认 ...

  8. 下载Chrome浏览器离线安装包

    下面提供了window和Mac OS两个版本的Chrome离线版本: Windows版本 Mac OS版本 说明 基本格式是在 chrome 首页的链接 https://www.google.com/ ...

  9. ST表略解

    题面 给定一个长度为\(N\)的数列,和\(M\)次询问,求出每一次询问的区间内数字的最大值. 对于30%的数据,满足: \(1≤N,M≤10\) 对于70%的数据,满足: \(1≤N,M≤10^5\ ...

  10. Java以邮件附件的方式发送excel文件

    String to = "xxx@qq.com"; // 收件人的QQ邮箱 String from = "xxx@qq.com"; // 发件人的QQ邮箱 St ...