Double Queue
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 13258   Accepted: 5974

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:

0 The system needs to stop serving
K P Add client K to the waiting list with priority P
2 Serve the client with the highest priority and drop him or her from the waiting list
3 Serve the client with the lowest priority and drop him or her from the waiting list

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

题目大意:

  有三个操作,1 K P:设置点K的优先级为P;

        2 :输出优先级最高的点,并且删除该点

        3 :输出优先级最低的点,并且删除该点  

        0:退出

  用map处理,插入和查找的复杂度都为log n;

 #include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <stdio.h>
#include <map>
#include <string.h>
#include <stdlib.h>
using namespace std;
int main()
{
int T,a,P,K;
map<int,int>ID;
map<int,int>::iterator it;
while(scanf("%d",&a)!=EOF){
switch(a){
case :
scanf("%d%d",&P,&K);
ID[K]=P;break;
case :
if(ID.empty())printf("0\n");
else {
it=ID.end();it--;
printf("%d\n",it->second);
ID.erase(it);
}
break;
case :
if(ID.empty())printf("0\n");
else {
it=ID.begin();
printf("%d\n",it->second);
ID.erase(it);
}
break;
case : return ;
}
} return ;
}

【Map】Double Queue的更多相关文章

  1. 【POJ3481】【splay】Double Queue

    Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest ...

  2. 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】

    目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...

  3. 【CF618F】Double Knapsack(构造)

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

  4. 01 语言基础+高级:1-6 集合_day04【Map】

    day04 [Map] 主要内容 Map集合 教学目标 能够说出Map集合特点 使用Map集合添加方法保存数据 使用”键找值”的方式遍历Map集合 使用”键值对”的方式遍历Map集合 能够使用Hash ...

  5. 【LeetCode】队列 queue(共8题)

    [346]Moving Average from Data Stream [353]Design Snake Game [363]Max Sum of Rectangle No Larger Than ...

  6. PAT 天梯赛 L1-034. 点赞 【MAP】

    题目链接 https://www.patest.cn/contests/gplt/L1-034 AC代码 #include <cstdio> #include <cstring> ...

  7. 【map】p1184 高手之在一起

    题目背景 高手是可以复活的,这点我们大家都知道. 题目描述 高手列出了一个详尽的日程表,这次他要追求的则是一个心灵纯洁的小萝莉.他和她都是要上课的,但是也会有时间空闲,于是高手决定无时无刻都要跟着她. ...

  8. 【BFS】【map】hdu5925 Coconuts

    题意:一张n*m的网格图(n和m可以达到10^9),其中K个点是障碍物(不超过200个),问你没有被障碍物占据的点形成了几个连通块?并且输出各个连通块的大小. 容易证明,大小超过40000的连通块最多 ...

  9. 【点分治】【map】【哈希表】hdu4670 Cube number on a tree

    求树上点权积为立方数的路径数. 显然,分解质因数后,若所有的质因子出现的次数都%3==0,则该数是立方数. 于是在模意义下暴力统计即可. 当然,为了不MLE/TLE,我们不能存一个30长度的数组,而要 ...

随机推荐

  1. [转]loadView的用法,loadView创建基本界面,DidLoad读入数据

    loadview: //   有没有nib 只要是复写了loadview loadview都会被执行     有nib文件的话加载的是nib文件的view  没有的话会按照loadview里的代码加载 ...

  2. Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同

    Azure的两种关系型数据库服务:SQL Azure与SQL Server VM的不同 <Windows Azure Platform 系列文章目录> 如果熟悉Windows Azure平 ...

  3. jquery 实现飘落效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. JavaScript插件——标签页

    JavaScript插件——标签页 前言 阅读之前您也可以到Bootstrap3.0入门学习系列导航中进行查看http://www.cnblogs.com/aehyok/p/3404867.html ...

  5. 《cracking the coding intreview》——链表

    前言 最近准备暑假回家回家修整一下,所以时间大部分用来完成项目上的工作,同时为了9月份的校招,晚上的时间我还在学习<cracking the coding intreview>,第二章链表 ...

  6. [转]Introduction to Core Bluetooth: Building a Heart Rate Monitor

    ref:http://www.raywenderlich.com/52080/introduction-core-bluetooth-building-heart-rate-monitor The C ...

  7. learn objetive-c

    Cocoa Dev Central Objective-C Objective-C is the primary language used to write Mac software. If you ...

  8. 广告基本知识-ROI分解

    任何一个在线广告系统,都面临ROI的问题,对于Invest,我们先不考虑,因为对于流量有多种方式可以买回,也无法优化(当然在RTB的时候是可以优化的).Return是主要优化的方向,Return=点击 ...

  9. ubuntu 学习笔记3--shell入门-if空格问题

    对于if语句是shell编程的基础,但是按照教程写出的就会出错 ./bash1.sh: : ./bash1.sh: if[: not found true ./bash1.sh: : ./bash1. ...

  10. Android Device Chooser中显示Target unknown解决方法

    手机插在电脑上准备调试程序来着,通过eclipse运行时,弹出的Android Device Chooser中显示设备名是?????,Target未知,无法继续运行. 可以通过以下步骤解决(Ubunt ...