zoukankan      html  css  js  c++  java
  • H

    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!

    按优先度,然后相同的FIFO,不能用vector然后自己排,复杂度太高会T,只能用优先队列;

    #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 mm(x,b) memset((x),(b),sizeof(x))
    #include<vector>
    #include<queue>
    #include<stack>
    #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;
    typedef long double ld;
    typedef double db;
    const ll mod=1e9+100;
    const db e=exp(1);
    using namespace std;
    const double pi=acos(-1.0);
    struct pp
    {
    	char name[20];
    	int num,lev,id;
     	friend bool operator <(pp a,pp b)
    	 {
    	 	if(a.lev ==b.lev)
    	 	return a.id >b.id ;//要加个这个,符合FIFO,不然会错
    	 	return a.lev >b.lev;
    	  } 
    };
    priority_queue<pp>v;
    void Get()
    {
    	if(v.empty()) pf("EMPTY QUEUE!
    ");
    	else{
    		pp t=v.top();
    		pf("%s %d
    ",t.name,t.num);
    		v.pop();	
    	}
    }
    int main()
    {
    	int ans=1;
    	while(!v.empty()) v.pop();
    	char q[5];
    	while(~sf("%s",q))
    	{
    		if(q[0]=='G')
    		Get();
    		else
    		{
    			pp t;
    			sf("%s%d%d",t.name,&t.num,&t.lev);
    			t.id =ans++;
    			v.push(t); 
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    Codeforces Round #669 (Div. 2) A、B题题解
    【证明】树上问题-树的直径
    Web前端开发——概述
    Codeforces Round #667 (Div. 3) A
    Codeforces Round #529 (Div. 3) 练习赛
    [Noip2012] 开车旅行 (倍增DP,难)
    国家集训队论文列表(1999-2019)
    博弈论经典模型解析(入门级)
    Problem 1342B
    SCOI2005 互不侵犯 (状态压缩入门题)
  • 原文地址:https://www.cnblogs.com/wzl19981116/p/9408144.html
Copyright © 2011-2022 走看看