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 ...
随机推荐
- linux系统取证
目录 0x00 查看系统信息 0x01 用户及组信息 0x02 防火墙及路由信息 0x03 查看网络.端口信息 0x04 系统运行信息查看 0x05 日志查看分析 0x00 查看系统信息 name-a ...
- ssh-keygen创建证书
ssh-keygen安装请参考以下内容:https://blog.csdn.net/a419419/article/details/80021684 (可能我已经安装过git了,所以不需要安装,具体细 ...
- opencv::模糊图像2
中值滤波 统计排序滤波器 中值对椒盐噪声有很好的抑制作用 medianBlur(Mat src, Mat dest, ksize) 双边滤波 均值模糊无法克服边缘像素信息丢失缺陷.原因是均值滤波是基于 ...
- spring boot打印sql语句-mybatis
spring boot打印sql语句-mybatis 概述 当自己编写的程序出现了BUG等等,找了很久 调试运行了几遍到mapper层也进去调试进了源码,非常麻烦 我就想打印出sql语句,好进行解决B ...
- [UWP]使用GetAlphaMask制作阴影
1. 前言 最近常常接触到GetAlphaMask,所以想写这篇文章介绍下GetAlphaMask怎么使用.其实GetAlphaMask的使用场景十分有限,Github上能搜到的内容都是用来配合Dro ...
- office visio 2019 下载激活
安装 下载 office ed2k://|file|cn_office_professional_plus_2019_x86_x64_dvd_5e5be643.iso|3775004672|1E4FF ...
- float使用0xFF
1. float f = 0xFFFFFFFF; 这一句完全是错误的用法,它不会使f变量内存变为4个0xFF,因为0xFFFFFFFF根本就不是有效的float数值,编译器无从处理,如果用printf ...
- 图数据库PageRank算法
目录: 定义 计算原理 定义: 假设对象A具有指向它的对象T1 ... Tn.参数d是阻尼系数,取值范围在0和1之间,通常将d设置为0.85.C(A)被定义为从对象A出去的连接数. 对象A的PageR ...
- AI Conference 2018人工智能大会 参会总结
主 题:AI Conference 2018人工智能大会 时 间:2018.04.11-4.13 地 点:北京国际饭店会议中心 发起人:O'Reilly 和 Intel 参与部门:研发设计部 参会人员 ...
- JDK JRE JVM的区别与关系
JDK JAVA开发工具包 他包含了JRE JAVA运行环境 JVM JAVA虚拟机他是跨平台的核心主件 他将Java源文件编译成 .class结尾字节码文件交由不同计算机执行 ...