首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >POJ 3481 Double Queue

POJ 3481 Double Queue

作者头像
Michael阿明
发布于 2021-02-20 10:38:52
发布于 2021-02-20 10:38:52
8110
举报

题目链接:http://poj.org/problem?id=3481

题目大意:

给你0-3四个指令: 0 退出 1 添加优先级为P 的 K值,进入队列 2 最高优先级出队 3 最低优先级出队

思路:

利用map数据对key默认升序排列。

AC代码如下:

代码语言:javascript
复制
#include<map>
#include<iostream>
using namespace std;
int main()
{
	map<int, int> doubleQueue;
	map<int, int>::iterator it;
	int function, key, value;
	while(scanf("%d",&function) && function)
	{
		if(function == 1)
		{
			scanf("%d%d",&value,&key);
			doubleQueue.insert(pair<int, int>(key, value));
		}
		else if(function == 2)
		{
			if(doubleQueue.size() == 0)
				printf("0\n");
			else
			{
				it = doubleQueue.end();
				printf("%d\n",(--it)->second);
				doubleQueue.erase(it);
			}
		}
		else if(function == 3)
		{
			if(doubleQueue.size() == 0)
				printf("0\n");
			else
			{
				it = doubleQueue.begin();
				printf("%d\n",it->second);
				doubleQueue.erase(it);
			}
		}
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019/05/04 ,如有侵权请联系 cloudcommunity@tencent.com 删除
目录
  • 题目链接:http://poj.org/problem?id=3481
  • 题目大意:
  • 思路:
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档