Problem Description
The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of the
bank is identified by a positive integer K and, upon arriving to the bank for some services, he or she receives a positive integer priority P. One of the inventions of the young managers of the bank shocked the software engineer of the serving system. They
proposed to break the tradition by sometimes calling the serving desk with the lowest priority instead of that with the highest priority. Thus, the system will receive the following types of request:



Your task is to help the software engineer of the bank by writing a program to implement the requested serving policy.


 
Input
Each line of the input contains one of the possible requests; only the last line contains the stop-request (code 0). You may assume that when there is a request to include a new client in the list (code 1), there is no other request
in the list of the same client or with the same priority. An identifier K is always less than 106, and a priority P is less than 107. The client may arrive for being served multiple times, and each time may obtain a different priority.


 
Output
For each request with code 2 or 3, the program has to print, in a separate line of the standard output, the identifier of the served client. If the request arrives when the waiting list is empty, then the program prints zero (0) to
the output.


 
Sample Input
2
1 20 14
1 30 3
2
1 10 99
3
2
2
0
 
Sample Output
0
20
30
10
0 STL乃神器。set的使用。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<set>
using namespace std;
struct node{
int v,p;
bool operator<(const node &a)const//p大的优先
{ return p>a.p; }
}; int main()
{
int u;
set<node>q;
node temp;
while(~scanf("%d",&u))
{
if(u==0)
break;
if(u==1)
{
scanf("%d%d",&temp.v,&temp.p);
q.insert(temp);
}
else if(q.empty())
puts("0");
else if(u==2)
{
printf("%d\n",q.begin()->v);
q.erase(q.begin());
}
else
{
set<node>::iterator it=q.end();
it--;
printf("%d\n",it->v);
q.erase(it);
}
}
return 0;
}

HDU 1908 Double Queue(set)的更多相关文章

  1. hdu 1908 Double Queue

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...

  2. POJ 3481 &amp; HDU 1908 Double Queue (map运用)

    题目链接: PKU:http://poj.org/problem?id=3481 HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908 Descript ...

  3. hdu 1387 Team Queue (链表)

    题目大意: 不同的人在不同的队伍里,插入链表的时候假设这个链表里有他的队友,就把它放到最后一个队友的最后.假设没有队友,就把它放到整个链表的最后面. 出链表的时候把第一个人拿出来. 思路分析: 要模拟 ...

  4. HDU 5938 Four Operations(四则运算)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  5. HDU 5775 Bubble Sort(冒泡排序)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  6. HDU 1711 Number Sequence(数列)

    HDU 1711 Number Sequence(数列) Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...

  7. HDU 1005 Number Sequence(数列)

    HDU 1005 Number Sequence(数列) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Jav ...

  8. 【CF618F】Double Knapsack(构造)

    [CF618F]Double Knapsack(构造) 题面 洛谷 Codeforces 题解 很妙的一道题. 发现找两个数集很不爽,我们强制加强限制,我们来找两个区间,使得他们的区间和相等. 把区间 ...

  9. HDU 1176 免费馅饼 (动态规划)

    HDU 1176 免费馅饼 (动态规划) Description 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼 ...

随机推荐

  1. Thinkphp5 模型 验证器执行顺序问题

    Thinkphp5把模型的验证规则归为一个验证器,这种做法,不知到符不符合大家的心意,反正楼主是比较不爽的 楼主更倾向于tp3.2的验证规则直接写在模型里面,毕竟你的验证规则一般而言是针对模型来验证的 ...

  2. 07.十分钟学会tomcat数据源

    一.数据源的作用及操作原理 1,  首先先看下传统JDBC的操作 在tomcat中使用数据库连接池操作数据库 2,JNDI属于命名及目录查找接口,在javaee的javax.naming包中 这套AP ...

  3. Python 解LeetCode:367. Valid Perfect Square

    题目描述:给出一个正整数,不使用内置函数,如sqrt(),判断这个数是不是一个数的平方. 思路:直接使用二分法,貌似没啥好说的.代码如下: class Solution(object): def is ...

  4. Spring+Spring MVC+MyBatis框架集成

    目录 一.新建一个基于Maven的Web项目 二.创建数据库与表 三.添加依赖包 四.新建POJO实体层 五.新建MyBatis SQL映射层 六.JUnit测试数据访问 七.完成Spring整合My ...

  5. C# WinForm程序添加启动画面

    如果程序在装载时需要进行较长时间的处理,最好使用启动画面,一方面美化程序,一方面可以不使用户面对着一片空白的程序界面. 我手头上一个小项目主界面启动时需要检查用户文件及运行环境是否有效,需要一段时间处 ...

  6. C#利用UdpClient发送广播消息

    首先写个接受消息的客户端.这里偷了点懒,new UdpClient(11000)就是用Udp方式侦听11000端口,侦听任何发送到11000端口的消息都会接收到. 代码 : ); Byte[] sen ...

  7. [转载] Hibernate与 MyBatis的比较

    转载自http://blog.csdn.net/firejuly/article/details/8190229 最近做了一个Hibernate与MyBatis的对比总结,希望大家指出不对之处. 第一 ...

  8. SpringMV---params and headers

      配置文件承接一二章    params params:请求的参数    params=value 表示请求过来的参数必须等于value    params!=value 表示请求过来的参数必须不等 ...

  9. oracle数据库创建表,序列及添加代码案例

    create table cdpt( id number(6), name varchar2(30), constraint pk_id primary key(id) ); 更改数据库的“延迟段创建 ...

  10. 洛谷 P3391 【模板】文艺平衡树

    题目背景 这是一道经典的Splay模板题--文艺平衡树. 题目描述 您需要写一种数据结构,来维护一个有序数列,其中需要提供以下操作:翻转一个区间,例如原有序序列是5 4 3 2 1,翻转区间是[2,4 ...