题目链接:http://poj.org/problem?id=3481
题目大意:
给你0-3四个指令:
0 退出
1 添加优先级为P 的 K值,进入队列
2 最高优先级出队
3 最低优先级出队
思路:
利用map数据对key默认升序排列。
AC代码如下:
#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;
}