Windows Message Queue (优先队列的应用)
来源:互联网 发布:编程证书 编辑:程序博客网 时间:2024/05/18 08:32
Windows Message Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7228 Accepted Submission(s): 2932
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
GETPUT msg1 10 5PUT msg2 10 4GETGETGET
Sample Output
EMPTY QUEUE!msg2 10msg1 10EMPTY QUEUE!
Author
ZHOU, Ran
Source
Zhejiang University Local Contest 2006, Preliminary
这也是一道优先队列的题;
PUT string a b 按b的优先级入队,b小优先级越高 b一样按先后顺序来
GET 输入对头并出队
#include<iostream>
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
string g="GET";
struct node{
friend bool operator < (node n1, node n2)
{
if(n1.a!=n2.a)
{
return n1.a>n2.a;//按最后那个数,越小越优先
}
return n1.k>n2.k;//按进入的顺序,也是
}
string s;
int v;
int a;
int k;
};
string b;
string c;
int main()
{
priority_queue<node >q;
int k=1;
while(cin>>c)
{
if(c==g)
{
if(q.empty())
{
cout<<"EMPTY QUEUE!"<<endl;
}
else
{
cout<<q.top().s<<" "<<q.top().v<<endl;
q.pop();
}
}
else
{
node e;
cin>>e.s>>e.v>>e.a;
e.k=k;
q.push(e);
k++;
}
}
}
#include<cstdio>
#include<string>
#include<queue>
using namespace std;
string g="GET";
struct node{
friend bool operator < (node n1, node n2)
{
if(n1.a!=n2.a)
{
return n1.a>n2.a;//按最后那个数,越小越优先
}
return n1.k>n2.k;//按进入的顺序,也是
}
string s;
int v;
int a;
int k;
};
string b;
string c;
int main()
{
priority_queue<node >q;
int k=1;
while(cin>>c)
{
if(c==g)
{
if(q.empty())
{
cout<<"EMPTY QUEUE!"<<endl;
}
else
{
cout<<q.top().s<<" "<<q.top().v<<endl;
q.pop();
}
}
else
{
node e;
cin>>e.s>>e.v>>e.a;
e.k=k;
q.push(e);
k++;
}
}
}
人一我百!人十我万!永不放弃~~~怀着自信的心,去追逐梦想。
阅读全文
1 0
- Windows Message Queue (优先队列的应用)
- Windows Message Queue(priority_queue优先队列)
- hdoj1509 Windows Message Queue (优先队列)
- Windows Message Queue(优先队列)
- hdu1509(Windows Message Queue) 优先队列
- Windows Message Queue(优先队列)
- hdu 1509 Windows Message Queue (简单STL的优先队列应用)
- Windows Message Queue(杭电oj1509)(优先队列)
- ZOJ 2724/HDU 1509 Windows Message Queue(优先队列)
- HDOJ 1509 Windows Message Queue (优先队列)
- HDU1509题Windows Message Queue(优先队列)
- hdu 1509 Windows Message Queue(优先队列)
- zoj-2724 Windows Message Queue(二叉堆&&优先队列)
- ZOJ 2724 Windows Message Queue (二叉堆,优先队列)
- HDU 1509 -- Windows Message Queue(优先队列)
- HDU 1509 Windows Message Queue(优先队列)
- HDOJ 1509 Windows Message Queue (简单优先队列 )
- HDOJ 1509 Windows Message Queue(优先队列)
- C++读入优化模板
- 架设私人版本控制工具,Ubuntu16.04设置GitLab CE服务器
- 【MongoDB】github版源码编译报错
- HDU 6040 Hints of sd0061(STL nth_element函数)
- 深入理解javascript原型和闭包(1)——一切都是对象
- Windows Message Queue (优先队列的应用)
- Qt Creator:对象模型
- 用Unity 3D生成真实地形(一)
- 【libffi】动态调用&定义C函数
- A simple math problem
- 关于四次挥手的事儿
- 大话设计模式-Study-Tips-第三章-装饰模式
- jsp超强技能树
- LruCache原理分析