来源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的更多相关文章

  1. hdu 1509 Windows Message Queue

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

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

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

  3. Windows Message Queue(优先队列)

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

  4. Windows Message Queue

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

  5. zoj 2724 Windows Message Queue

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

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

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

  7. HDU 1509 Windows Message Queue(队列)

    题目链接 Problem Description Message queue is the basic fundamental of windows system. For each process, ...

  8. H - Windows Message Queue

    Message queue is the basic fundamental of windows system. For each process, the system maintains a m ...

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

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

随机推荐

  1. 登录页面和FORM的职责不对称,处理方法,刷新工作流程

    登录页面和FORM的职责不对称,处理方法,刷新工作流程:

  2. Exception in thread "main" java.lang.StackOverflowError at java.util.ArrayList$SubList.rangeCheckForAdd(Unknown Source)

    Exception in thread "main" java.lang.StackOverflowError at java.util.ArrayList$SubList.ran ...

  3. 通过脚本调用MSBuild编译项目时指定Configuration(解決方案配置)和Platform(解決方案平台),Rebuid(重新生成解决方案),Clean(清理解决方案)

    为了方便打包测试,自己PowerShell写了一个编译和发布的脚本,调用msbuild通过命令行来编译当前解决方案 后来发现一个问题,用VS编译解决方案,我通过 项目属性-Build设置 Releas ...

  4. mysql百分比显示

    select doll_name, type, value concat( left(get /(get+ fall)*100, 5), '%') as 抓取概率 from doll_conf

  5. 【MySQL】MySQL中查询出数据表中存在重复的值list

    1.目的:查询MySQL数据表中,重复记录的值 2.示例: 3.代码: select serial_num,count(*) as count FROM card_ticket GROUP BY se ...

  6. 转载:MVC升级以后出现"当前上下文中不存在ViewBag"的问题解决

    MVC升级以后出现"当前上下文中不存在ViewBag"的问题解决 把自己的项目从MVC4升级到了MVC5,结果问题一大堆,View的设计环境出现了"当前上下文中不存在Vi ...

  7. python数据分析实用小抄

    1. python数据分析基础 2. numpy 3. Scikit-Learn 4. Bokeh 5. Scipy 6. Pandas   转载于:http://www.jianshu.com/p/ ...

  8. Linux 搭建git 自己拉取本地 git pull,其他地方的git仓库拉取代码

    Linux 下建立 Git 与 GitHub 的连接 Git 是一款开源的分布式版本控制系统,而 GitHub 是依托 Git 的代码托管平台. GitHub 利用 Git 极其强大的克隆和分支功能, ...

  9. Mathematica绘制曲面交线方法(方法二)

    MeshFunction方式 Show[Graphics3D[{Opacity[0.5], Ball[{0, 0, 0}, 2]}], ParametricPlot3D[{4 + (3 + Cos[v ...

  10. spring 中单例 bean 初始化之后和销毁之前执行指定动作 postconstruct 和 preDestroy

    1 生命周期方法, 在指定bean 创建完成后执行初始化动作或销毁之前做一些善后动作.有 3 种方法 1)实现接口 InitializingBean 然后实现 afterPropertiesSet 方 ...