ZOJ2724_Windows Message Queue(STL/优先队列)
解题报告
题意:
看输入输出就非常明确。
思路:
优先队列。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <vector>
#include <cstdio>
#include <map> using namespace std;
struct node {
char m[100];
int v,k;
friend bool operator <(node a,node b) {
return a.k>b.k;
}
};
priority_queue<node>Q;
int main() {
char str[100],str1[1000];
int a,b;
while(~scanf("%s",str)) {
if(strcmp(str,"GET")==0) {
if(Q.empty())
printf("EMPTY QUEUE!\n");
else {
node a=Q.top();
Q.pop();
printf("%s %d\n",a.m,a.v);
}
} else if(strcmp(str,"PUT")==0) {
scanf("%s%d%d",str1,&a,&b);
node o;
strcpy(o.m,str1);
o.v=a;
o.k=b;
Q.push(o);
}
}
return 0;
}
Windows Message Queue
Time Limit: 2 Seconds Memory Limit: 65536 KB
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!
ZOJ2724_Windows Message Queue(STL/优先队列)的更多相关文章
- Windows Message Queue(优先队列)
欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Mem ...
- hdu1509(Windows Message Queue) 优先队列
点击打开链接 Problem Description Message queue is the basic fundamental of windows system. For each proces ...
- hdoj 1509 Windows Message Queue【优先队列】
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- hdu 1509 Windows Message Queue (优先队列)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...
- hdu 1509 Windows Message Queue (优先队列)
Windows Message QueueTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...
- 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, ...
- CJOJ 2484 函数最小值 / Luogu 2085 函数最小值(STL优先队列,堆)
CJOJ 2484 函数最小值 / Luogu 2085 函数最小值(STL优先队列,堆) Description 有n个函数,分别为F1,F2,...,Fn.定义 \(Fi(x)=Aix^2+Bix ...
随机推荐
- 洛谷 P2986 [USACO10MAR]Great Cow Gat…(树形dp+容斥原理)
P2986 [USACO10MAR]伟大的奶牛聚集Great Cow Gat… 题目描述 Bessie is planning the annual Great Cow Gathering for c ...
- Appium + python -小程序实例
from appium import webdriverfrom appium.webdriver.common.touch_action import TouchActionfrom time im ...
- 关于sklearn中的导包交叉验证问题
机器学习sklearn中的检查验证模块: 原版本导包: from sklearn.cross_validation import cross_val_score 导包报错: 模块继承在cross_va ...
- A - High School: Become Human
Problem description Year 2118. Androids are in mass production for decades now, and they do all the ...
- java中equals方法和==的用法
java中equals方法的用法以及==的用法(参考一)equals 方法是 java.lang.Object 类的方法.两种用法说明:(1对于字符串变量来说,使用“==”和“equals()”方法比 ...
- SLAM:ORB-SLAM 位姿优化描述
只知道算法描述和代码,而不知道原理是比较扯的事情,还是把原理转载一下. 原文链接: http://www.cnblogs.com/luyb/p/5447497.html ORB-SLAM作为单目SLA ...
- 一个完整的jmeter APP登录接口测试实例
最终效果: 知识点: 通过HTTP信息头管理器, 正则表达式提取器 提取登录要用的token,memcard,Debug Sampler,CSV Data set config参数化登录,循环控制器 ...
- Webpack 快速上手(下)
杏仁前端开发工程师,代码洁癖症早期,关注前端技术. 由于文章篇幅较长,为了更好的阅读体验,本文分为上.中.下三篇: 上篇介绍了什么是 webpack,为什么需要 webpack,webpack 的文件 ...
- 继承(day09)
二十一 继承(Inheritance) ... 子类的构造函数和析构函数 5.1 子类的构造函数 )如果子类构造函数没有显式指明基类子对象的初始化方式,那么该子对象将以无参方式被初始化. )如果希望基 ...
- 【密码学】RSA加密 kotlin实现方法(支持任意字节长度)
这个编辑器不支持kotlin,尴尬了···· 算了,就用Java来弄吧 val 定义常量 var 定义变量 具体kotlin的开发手册详见:http://www.runoob.com/kotlin/k ...