题目链接

Problem Description
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!

题解:优先队列,写的时候运算符重载一直出问题,还是不懂。而且刚开始没有加idx这个成员,就一直WA,看了看题目也没发现什么诡异的地方,最后看了几个题解,加上了idx就AC了,也不知道是为什么。

#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <map>
#define PI acos(-1.0)
#define ms(a) memset(a,0,sizeof(a))
#define msp memset(mp,0,sizeof(mp))
#define msv memset(vis,0,sizeof(vis))
using namespace std;
//#define LOCAL
struct task
{
char name[];
int value,pri,idx;
friend bool operator < (task a,task b)
{
if(a.pri==b.pri)
{
return b.idx<a.idx;
}
return b.pri<a.pri;
}
} t;
int main()
{
#ifdef LOCAL
freopen("in.txt", "r", stdin);
#endif // LOCAL
ios::sync_with_stdio(false);
priority_queue<task> q;
//while(!q.empty())q.pop();
char com[];
int k=;
while(cin>>com)
{
if(com[]=='G')
{
if(q.empty())printf("EMPTY QUEUE!\n");
else printf("%s %d\n",q.top().name,q.top().value),q.pop();
}
else
{
cin>>t.name>>t.value>>t.pri;
t.idx=++k;
q.push(t);
}
}
return ;
}

HDU 1509 Windows Message Queue(队列)的更多相关文章

  1. hdu 1509 Windows Message Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...

  2. hdu 1509 Windows Message Queue (优先队列)

    Windows Message QueueTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  3. hdu 1509 Windows Message Queue (优先队列)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1509 题目大意:每一次输入都有序号和优先级,优先级小的先输出,优先级相同的话则序号小的先输出!第一次用 ...

  4. hdoj 1509 Windows Message Queue【优先队列】

    Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Ot ...

  5. MSMQ学习笔记二——创建Message Queue队列

    一.创建Message Queue队列的主要流程 1.定义MQQUEUEPROPS 结构: 2.设置消息队列属性: 3.初始化MQQUEUEPROPS 结构: 4.调用MQCreateQueue创建队 ...

  6. Windows Message Queue(优先队列)

    欢迎参加——BestCoder周年纪念赛(高质量题目+多重奖励) Windows Message Queue Time Limit: 2000/1000 MS (Java/Others)    Mem ...

  7. Windows Message Queue

    Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Other ...

  8. zoj 2724 Windows Message Queue

    Windows Message Queue Time Limit: 2 Seconds      Memory Limit: 65536 KB Message queue is the basic f ...

  9. zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...

随机推荐

  1. SUSElinux的pam模块中$ISA变量的作用

    目的:限制非wheel用户切换至root 方法:vi /etc/pam.d/su文件,增加如下两行 auth sufficient /lib/security/pam_rootok.soauth re ...

  2. layoutSubviews在什么情况下会被调用

    layoutSubviews在以下情况下会被调用: 1.init初始化不会触发layoutSubviews. 2.addSubview会触发layoutSubviews. 3.设置view的Frame ...

  3. 【转】http://www.cnblogs.com/yuzukwok/p/3884377.html

    来自:http://www.cnblogs.com/yuzukwok/p/3884377.html An Introduction to Xamarin.Forms 来源:http://develop ...

  4. 导入导出Mysql数据库、表结构、表数据

    由sql文件导入 mysql -uusername -ppwd < ./abc.sql 导出整个数据库的表结构 mysqldump -uroot -pdbpasswd -d dbname > ...

  5. 搭建git代码服务器

    在代码管理中,通常需要使用版本管理工具,git就是一个不错的选择,这里简单罗列一下git服务器的搭建过程. 1. 安装git工具包 2. 初始化git库:在代码服务器上,通常只需要创建一个不含有工作目 ...

  6. centos-mysql 安装

    初学者自编文档,如有错误,请指出,具体命令就不阐述了,不明白 度娘吧! nginx我是编译安装在服务器上 和其他安装应该会有区别 安装路径路径:/usr/local/ 安装包存放位置:/home/ap ...

  7. 集成shareSDK的微信、QQ API导致cocoaPods找不到类symbol问题的解决方法

    因为shareSDK的微信和QQ API都只支持32位的,而cocoaPods默认要支持64位的,所以如果在工程中导入这两个API会出问题. 解决方法我就不转载啦,原文在这里: http://blog ...

  8. 各个Maven仓库镜像(包括国内)

    各个Maven仓库镜像(包括国内) 衽孤魍墓 ゅ槭 众矿工唯唯诺诺我在旁哭笑不得原 宦蠃サ 骘猩池 粑涫汾滹 吧滔哌蹋 飑俗た 狃攵庾唾 想必是想挡住什么我想反正这笔筒也不是 翡蜮胼 娴左 ...

  9. json_encode不编码中文字符的方式

    json_encode($array,JSON_UNESCAPED_UNICODE);

  10. 一个初学者的辛酸路程-python操作SQLAlchemy-13

    前言 其实一开始写blog,我是拒绝的,但是,没办法,没有任何理由抗拒.今天呢,要说的就是如何使用Python来操作数据库. SQLAlchemy SQLAlchemy是Python编程语言下的一款O ...