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 ...
随机推荐
- 使用 Polyfill 而不再是 bable 来实践js新特性
现状 我们想要用ES6 语法来写 JavaScript.然而由于我们需要兼容老版本的浏览器,那些浏览器不支持 ES6,我们需要解决这个问题. 有一个标准的做法是:写 ES6 代码 → 将所有代码编译成 ...
- javascript从作用域链的角度看闭包
闭包 闭包是一个能访问外部函数定义的变量的函数. 为什么? 当访问一个变量时,解释器会首先在当前作用域查找标示符,如果没有找到,就去父作用域找,直到找到该变量的标示符或者不再存在父作用域了,这就是作用 ...
- Django day24 cbv和APIView的源码分析 和 resful的规范
一:cbv的源码分析 1.CBV和FBV的区别: - Class Base View CBV(基于类的视图) - Function Base View FBV(基于函数的视图) 2.as_vi ...
- CAS配置(2)之主配置
WEB-INF目录 1.cas.properties文件(打开关闭SSL,主题,定制页面设置) #默认端口配置 #server.name=http://localhost:8080server.nam ...
- 【区间DP】释放囚犯
貌似和石子合并差不多 可能是我见的题太少了,所以都差不多 OK 算法分析 首先不难看出这是一道区间DP,那么,按照本蒟蒻的意思 区间DP==三个循环 for(int len=2;len<=n;l ...
- B - Magnets
Problem description Mad scientist Mike entertains himself by arranging rows of dominoes. He doesn't ...
- CentOS 安装dotNetCore
如果要在CentOS上运行.net Core程序,必须安装.net Core Sdk 具体安装 方法,可以参考微软官方站点说明,非常详细: 1)百度搜索 .Net Core 2)先择CentOS版本: ...
- 编码的来历和使用 utf-8 和GB2312比较
经常我们打开外国网站的时候出现乱码,又或者打开很多非英语的外国网站的时候,显示的都是口口口口口的字符, wordpress程序是用的UTF-8,很多cms用的是GB2312. ● 为什么有这么多编码? ...
- Excel 批量出来数据
try { string sheetname = TextBox1.Text.Trim(); HttpPostedFile upLoadPostFile = FileUpload1.PostedFil ...
- 英语之ASIC
ASIC(Application Specific Integrated Circuit) = 专用集成电路 assign = [计][数] 赋值 assign a value 分配一个值:赋值