D - Windows Message Queue
来源hdu1509
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!
按价值排序,优先队列水题
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include <iomanip>
#include<cmath>
#include<float.h>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define scf(x) scanf("%d",&x)
#define scff(x,y) scanf("%d%d",&x,&y)
#define prf(x) printf("%d\n",x)
#define mm(x,b) memset((x),(b),sizeof(x))
#include<vector>
#include<queue>
#include<map>
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=a;i>=n;i--)
typedef long long ll;
const ll mod=1e9+7;
const double eps=1e-8;
const int inf=0x3f3f3f3f;
using namespace std;
const double pi=acos(-1.0);
const int N=3e2+10;
class mes
{
public:
char name[50];
int cnt;
int num,val;
friend bool operator <(mes a,mes b)
{
if(a.val==b.val)
return a.cnt>b.cnt;
return a.val>b.val;
}
};
priority_queue<mes> v;
void print(mes a)
{
pf("%s %d\n",a.name,a.num);
}
int main()
{
int cas=1;
char a[5];
while(~sf("%s",a))
{
if(a[0]=='G')
{
if(v.empty())
pf("EMPTY QUEUE!\n");
else
{
print(v.top());
v.pop();
}
}else
{
mes t;
t.cnt=cas++;
sf("%s%d%d",t.name,&t.num,&t.val);
v.push(t);
}
}
return 0;
}
D - Windows Message Queue的更多相关文章
- hdu 1509 Windows Message Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1509 Windows Message Queue Description Message queue ...
- hdoj 1509 Windows Message Queue【优先队列】
Windows Message Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- 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 ...
- hdu 1509 Windows Message Queue (优先队列)
Windows Message QueueTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- HDU 1509 Windows Message Queue(队列)
题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...
- H - Windows Message Queue
Message queue is the basic fundamental of windows system. For each process, the system maintains a m ...
- zoj 2724 Windows Message Queue(使用priority_queue容器模拟消息队列)
题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=2724 题目描述: Message queue is the b ...
随机推荐
- CiscoIOUKeygen
python CiscoIOUKeygen.py | grep -A 1 ‘license’ > iourc
- MAC 开启与关闭SIP
1. 查看SIP状态 在终端中输入csrutil status,就可以看到是enabled还是disabled. 2. 关闭SIP S1 重启MAC,按住cmd+R直到屏幕上出现苹果的标志和进度条, ...
- [web 前端] mobx教程(一)-mobx简介
opy from : https://blog.csdn.net/smk108/article/details/84777649 Mobx是通过函数响应式编程使状态管理变得简单和可扩展的状态管理库.M ...
- import tensorflow 报错: tf.estimator package not installed.
import tensorflow 报错: tf.estimator package not installed. 解决方案1: 安装 pip install tensorflow-estimator ...
- 转: 关于linux用户时间与系统时间的说明
写的很不错的一篇. https://blog.csdn.net/mmshixing/article/details/51307853
- 关于海康威视与Unity3d集成冲突问题解决
一.集成 1.1 了解什么是ANSI系列与GNU系列 https://baike.baidu.com/item/ANSI%20C/7657277?fr=aladdin https://ww ...
- 【centos6.6环境搭建】Github unable to access SSL connect error出错处理
问题 克隆github项目出现SSL connect error git clone https://github.com/creationix/nvm Cloning into 'nvm'... f ...
- 实战UITableview深度优化
演示项目下载地址:https://github.com/YYProgrammer/YYTableViewDemo 项目里的低性能版是常规写法实现的tableview,高性能版是做了相关优化后的tabl ...
- 让rpc支持双向通信
rpc采用了C/S模型,不支持双向通信:client只能远程调用server端的RPC接口,但client端则没有RPC供server端调用,这意味着,client端能够主动与server端通信,但s ...
- 说说erlang tuple和record结构
erlang有两种复合结构.tuple和list,两者的区别是tuple子元素的个数是固定不变的.声明后就不能改变了.而list是可变的,能够通过[H|T]来取出或插入新元素. record有点像C/ ...