【Map】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 |
1 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的更多相关文章
- 【POJ3481】【splay】Double Queue
Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest ...
- 【第40套模拟题】【noip2011_mayan】解题报告【map】【数论】【dfs】
目录:1.潜伏者 [map] 2.Hankson的趣味题[数论]3.mayan游戏[dfs] 题目: 1. 潜伏者(spy.pas/c/cpp)[问题描述]R 国和S 国正陷入战火之中,双方都互派间谍 ...
- 【CF618F】Double Knapsack(构造)
[CF618F]Double Knapsack(构造) 题面 洛谷 Codeforces 题解 很妙的一道题. 发现找两个数集很不爽,我们强制加强限制,我们来找两个区间,使得他们的区间和相等. 把区间 ...
- 01 语言基础+高级:1-6 集合_day04【Map】
day04 [Map] 主要内容 Map集合 教学目标 能够说出Map集合特点 使用Map集合添加方法保存数据 使用”键找值”的方式遍历Map集合 使用”键值对”的方式遍历Map集合 能够使用Hash ...
- 【LeetCode】队列 queue(共8题)
[346]Moving Average from Data Stream [353]Design Snake Game [363]Max Sum of Rectangle No Larger Than ...
- PAT 天梯赛 L1-034. 点赞 【MAP】
题目链接 https://www.patest.cn/contests/gplt/L1-034 AC代码 #include <cstdio> #include <cstring> ...
- 【map】p1184 高手之在一起
题目背景 高手是可以复活的,这点我们大家都知道. 题目描述 高手列出了一个详尽的日程表,这次他要追求的则是一个心灵纯洁的小萝莉.他和她都是要上课的,但是也会有时间空闲,于是高手决定无时无刻都要跟着她. ...
- 【BFS】【map】hdu5925 Coconuts
题意:一张n*m的网格图(n和m可以达到10^9),其中K个点是障碍物(不超过200个),问你没有被障碍物占据的点形成了几个连通块?并且输出各个连通块的大小. 容易证明,大小超过40000的连通块最多 ...
- 【点分治】【map】【哈希表】hdu4670 Cube number on a tree
求树上点权积为立方数的路径数. 显然,分解质因数后,若所有的质因子出现的次数都%3==0,则该数是立方数. 于是在模意义下暴力统计即可. 当然,为了不MLE/TLE,我们不能存一个30长度的数组,而要 ...
随机推荐
- Linq to XML的练习
假如有以下XML: <?xml version="1.0" encoding="utf-8" ?> - <export> - <p ...
- 移动tempdb导致数据库服务不能启动
事情的起因是因为数据库的IO操作过大,于是新加了个硬盘,发现在执行写入操作的时候,服务器的压力依然是比较大的,于是想到了内存盘.内存盘是"魔方"系统优化提供的一个小工具,就是将内存 ...
- Vi编辑器入门
Vi编辑器入门 vi编辑器是所有Unix及Linux系统下标准的编辑器,类似于windows上的记事本! 1.vi的基本概念 基本上vi可以分为三种状态,分别是命令模式(command mode ...
- Windows7和Archlinux双系统硬盘安装笔记
俗话说,好记性不如烂笔头,这些东西也都是我Google来的,做个笔记以后自己安装也方便些. 因为官方wiki的Beginners' Guide讲的非常好,大部分步骤按照wiki一步一步来就好了,这里只 ...
- 简单的mvc之二:蜿蜒的管线
关于系列的第二篇,在管线与路由之间犹豫了很久,最终选择了管线—为免于盲人摸象的困惑. 管线的位置在哪里呢?webform,mvc以及web api都架构于asp.net平台上,管线则是asp.net的 ...
- xhEditor struts2实现图片上传
xhEditor的环境搭建请参考http://blog.csdn.net/itmyhome1990/article/details/38422255,这时我们打开图片功能 是没有上传按钮的 如果想要出 ...
- spring redis入门
小二,上菜!!! 1. 虚拟机上安装redis服务 下载tar包,wget http://download.redis.io/releases/redis-2.8.19.tar.gz. 解压缩,tar ...
- 解决中文乱码( jsp表单提交中文时出现乱码)
有三种方法: 1.建立一个filter中文解决乱码 2.Struts2在struts.xml中修改默认的编码设定 3.用Spring解决中文乱码 4.直接在jsp中修改解决 1.建立一个filter解 ...
- ios学习笔记(一)之Object-C
一:Objective-C语言基础 二:Objective-C类与继承和协议 一:Objective-C语言基础: 1.1)#import 包含头文件 与#include 作用相同 1.2)Obje ...
- “MVC+Nhibernate+Jquery-EasyUI”信息发布系统 第二篇(数据库结构、登录窗口、以及主界面)
“MVC+Nhibernate+Jquery-EasyUI”信息发布系统 第二篇(数据库结构.登录窗口.以及主界面) 一.在上一篇文章中,主要说的就是把主框架搭建起来,并且Nhibernate能达到增 ...