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 ...
随机推荐
- SpringBoot + MyBatis(注解版),常用的SQL方法
一.新建项目及配置 1.1 新建一个SpringBoot项目,并在pom.xml下加入以下代码 <dependency> <groupId>org.mybatis.spring ...
- [转]利用 NPOI 變更字體尺寸及樣式
本文转自:http://blog.cscworm.net/?p=1650 利用 NPOI 變更字體尺寸及樣式: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...
- C - Arrival of the General
Problem description A Ministry for Defense sent a general to inspect the Super Secret Military Squad ...
- 【转】SQL SERVER 主体,已同步
转自郭大侠博客: https://www.cnblogs.com/gered/p/10601202.html 目录 SQL SERVER 基于数据库镜像的主从同步... 1 1.概念... 2 1. ...
- C#url相关知识
C#中Url地址重定向的方法: 1:Response.Redirect(url); 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次postback),但他可以跳转到任何页面,没有站点页面限 ...
- JavaScript 判断手机端操作系统(Andorid/IOS)
androidURL = "http://xxx/xxx.apk"; var browser = { versions: function() { var u = navigato ...
- swift-delegate(代理)或者block传值
1:delegate或者block传值 import UIKit class ViewController: UIViewController,TestDelegatePassValueDelegat ...
- 富文本wangEditor的批量激活
最近项目中使用了wangEditor这个轻量级的富文本框,由于需求是一个页面中会有多个富文本框同时激活,所以写了个批量激活的jquery方法,分享一下 // 激活富文本框 var wangEditor ...
- Redis 之list链表结构及命令详解
1.lpush key value 从左放一个值 2.rpush key value 从右放一个值 3.lrange key start stop 获取链表数据(start ...
- python tips:最内嵌套作用域规则,闭包与装饰器
在作用域与名字空间提到,python是静态作用域,变量定义的位置决定了变量作用的范围.变量沿着local,global,builtins的路径搜索,直觉上就是从里到外搜索变量,这称为最内嵌套作用域规则 ...