【ZOJ - 2724】【HDU - 1509】Windows Message Queue(优先队列)

题干:

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!

解题报告:

   优先队列直接解。刚开始数组开太大了疯狂超内存。我还在node上加了个[MAX]  出现了这个报错 Segmentation Fault

AC代码:

#include<bits/stdc++.h>

using namespace std;
const int MAX = 6e4 + 5;
struct Node {
	int id;
	char name[400];
	int k;//参数
	int vip;
	//Node(int id,char name[MAX],int k,int vip):id(id),name(name),k(k),vip(vip){}
	bool operator<(const Node b) const {
		if(vip!=b.vip) return vip>b.vip;
		return id>b.id;
	}
} node;
priority_queue <Node> pq;
char tmpname[MAX];
int main()
{
	char op[10];
	int cnt = 0;
	int k,v;
	
	while(~scanf("%s",op) ) {
		if(op[0] == 'G') {
			if(!pq.empty() ) {
				Node cur = pq.top();
				pq.pop();
				printf("%s %d\n",cur.name,cur.k);
			}
			else printf("EMPTY QUEUE!\n");
		}
		else {
			cnt++;
			scanf("%s%d%d",tmpname,&k,&v);
			
			Node tmp;
			tmp.id = cnt;tmp.k = k;tmp.vip = v;
			strcpy(tmp.name,tmpname);
			pq.push(tmp);
		}
		
	}
	return 0 ;
}
全部评论

相关推荐

二十岁的编程男神王大...:读博吧兄弟,你这绩点太好了,何必转码,另外哈哈哈真见到有括号标出来985的,这个不标注也知道吧
点赞 评论 收藏
分享
头像
04-27 15:11
已编辑
华东师范大学 算法工程师
暑期实习从2月开始投,面了两个月,流程该挂的都挂完了,腾讯字节一共号称是1.7w个hc,不知道都发给谁了,估计今年秋招要难顶。Timeline米哈游、美团、蚂蚁、微软等公司直接简历挂穿,没进面。携程:3.3&nbsp;投递、测评3.12&nbsp;笔试3.18&nbsp;一面3.25&nbsp;二面4.13&nbsp;ai面(hr面)4.14&nbsp;英语测评4.23&nbsp;offer(已拒)腾讯:2.6&nbsp;测评2.28&nbsp;wxg一面3.5&nbsp;wxg二面(挂)3.11&nbsp;teg一面3.21&nbsp;teg二面(取消)3.31&nbsp;teg一面4.10&nbsp;teg二面(挂)4.21&nbsp;wxg一面4.24&nbsp;wxg二面(挂)字节:1.28&nbsp;aml约面(取消)3.17&nbsp;火山一面(挂)4.8&nbsp;aml一面(挂)4.20&nbsp;抖音data一面(挂)阿里:3.23&nbsp;投递、测评3.28&nbsp;笔试3.31&nbsp;淘天一面4.8&nbsp;钉钉一面4.9&nbsp;淘天二面4.10&nbsp;阿里控股一面4.12&nbsp;钉钉二面(取消)4.15&nbsp;淘天hr面4.16&nbsp;淘天offer(已接)4.21&nbsp;高德一面(取消)4.22&nbsp;淘宝闪购一面(取消)面试最大的感触是,现在撞上ai转型,一堆老业务急着转向,新业务非常不成熟,研究型的组bar非常高根本进不去,业务侧挂着算法的岗位干的都是工程活,面试却又要问算法,另外agent的落地也远没有那么广,绝大多数还是那套写死的系统调一下llm&nbsp;api或者做做rag,其余少部分真的在搭agent的,基本不能在线上服务用什么很智能的模型,现阶段成本太高,进去大概率就是给垃圾模型从工程方面兜底,除了业务场景的应用和数据经验以外,技术方面很难有什么提升。算法岗做不了基模的还是去搜广推好,之前判断失误了完全没投,秋招不知道还进不进得去。
嵌入式的小白:不错啊,淘天也是挺好的,恭喜
我的求职进度条
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务