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 ...
随机推荐
- C#读取邮件附件的方法
基于需求需要从邮件里读取附件,从网络搜索整理如下: 1 使用 Spire.Email 从官网下载安装并引用,地址:https://www.e-iceblue.com/Download/email-fo ...
- 基于Spring Boot的统一异常处理设计
基于Spring Boot的统一异常处理设计 作者: Grey 原文地址:https://www.cnblogs.com/greyzeng/p/11733327.html Spring Boot中,支 ...
- C语言 二叉树的遍历(递归和非递归)
#include <iostream> #include <cstdio> #include "biTree.h" #include "cstdl ...
- OptimalSolution(7)--大数据和空间限制
一.布隆过滤器 问题:不安全网页的黑名单包含100亿个黑名单网页,每个网页的URL最多占用64B.现在想要实现一种网页过滤系统,可以根据网页的URL判断该网页是否在黑名单上,如何设计该系统. 要求:允 ...
- js重点
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Springboot与任务整合(四)
一 异步任务 启动类 @MapperScan("com.topcheer.*.*.dao") @SpringBootApplication @EnableCaching @Enab ...
- JavaScript基础修炼(14)——WebRTC在浏览器中如何获得指定格式的PCM数据
目录 一. PCM格式是什么 二. 浏览器中的音频采集处理 三. 需求实现 方案1--服务端FFmpeg实现编码 方案2--ScriptProcessorNode手动处理数据流 参考文献 示例代码托管 ...
- 我的【Java】面试日记
背景 在老东家五年了,总共工作整七年,经历两家公司.2019-10-31日离职.公司规模较小,项目压力不大,非985/211毕业,统招本科,计算机专业.目标:中大型公司,最好是大厂,嘿嘿,不过不抱希望 ...
- Ubuntu16.04下nvidia驱动+nvidia-docker+cuda9+cudnn7安装
一.宿主机安装nvidia驱动 打开终端,先删除旧的驱动: sudo apt-get purge nvidia* 禁用自带的 nouveau nvidia驱动 sudo gedit /etc/modp ...
- JS 接口定义及实现的例子
//定义一个函数,目的是将参数中的第二个函数所有属性放到第一个参数中,目的是将接口中所有方法放到实现类中 Object.extend=function(destination,source){ for ...