hdu 1509 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
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.
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.
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.
GET
PUT msg1 10 5
PUT msg2 10 4
GET
GET
GET
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 (优先队列)的更多相关文章
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- HDU 1509 Windows Message Queue(队列)
题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...
- hdu 1509 Windows Message Queue (优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...
- hdoj 1509 Windows Message Queue【优先队列】
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- zoj 2724 Windows Message Queue 优先队列
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1724 题目大意: 给出两种操作,GET要求取出当前队首的元素,而PUT会输入名 ...
- Windows Message Queue(优先队列)
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Mem ...
- 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 ...
随机推荐
- [UWP]使用CompositionLinearGradientBrush实现渐变画笔并制作动画
1. 什么是 CompositionBrush CompositionBrush(合成画笔)是操作可视化层时用于绘制 SpriteVisual 区域的画笔. 使UWP 应用时可以选择使用 XAML 画 ...
- ubuntu16.04安装zlib
sudo apt-get install zlib1g-dev 下载:libzip-1.0.1.tar.gztar zxcv libzip-1.0.1.tar.gzcd libzip-1.0.1./c ...
- POJ 3020 Antenna Placement(二分图 匈牙利算法)
题目网址: http://poj.org/problem?id=3020 题意: 用椭圆形去覆盖给出所有环(即图上的小圆点),有两种类型的椭圆形,左右朝向和上下朝向的,一个椭圆形最多可以覆盖相邻的两 ...
- linux上war包方式安装Jenkins
我的安装环境:jdk1.8, linux系统为: [root@ipha-dev71-1 nmon]# cat /etc/redhat-release # Linux查看版本当前操作系统发行版信息 Ce ...
- 百万年薪python之路 -- 递归
递归(每当有一个函数被递归调用,就应该要有一个返回值,才能正常把递归的返回值'归'回来) 一个正经的递归: 1.不断调用自己本身 2.有明确的结束条件 递归注重于"一递 一归&quo ...
- Kafka权威指南阅读笔记(第五章)
Kafka Broker kafka 第一个启动的Broker在ZooKeeper中创建一个临时节点/controller,让自己成为控制器.其他Broker启动后在控制器节点上创建Watch对象,便 ...
- unity 开启外部摄像头
在unity中建立一个image作为摄像头显示画面,然后通过命令render到image上即可. public WebCamTexture webTex; public string deviceNa ...
- Java自动化测试框架-08 - TestNG之并行性和超时篇 (详细教程)
一.并行性和超时 您可以指示TestNG以各种方式在单独的线程中运行测试. 可以通过在suite标签中使用 parallel 属性来让测试方法运行在不同的线程中.这个属性可以带有如下这样的值: 二.并 ...
- 使用float设置经典的网站前端结构(深入探讨)
.要是DIV的子元素宽度大于它自己的宽度,不管子元素有没有脱离文档流,子元素会在横向向右溢出. 关于高度:1.要是DIV的高度没有设定,其高度受“没有脱离文档流”的子元素影响.以下是DIV宽度为0的情 ...
- Numpy 中的聚合操作
# 导包 import numpy as np sum np.random.seed(10) L = np.random.random(100) sum(L) np.sum(L) min np.min ...