【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长度的数组,而要 ...
随机推荐
- Day3:T1数论+高精 T2搜索
T1:数论+高精(水~) 根据题意可知,从除的数越大越好(在0~9中) 所以我们只要用到高精除然后再模拟一下就可以了 //MARK:但是要注意0-9这个特殊值需要特判,因为题目要求输出的数至少是两位数 ...
- baidu 200兆SVN代码服务器
转 今天心情好,给各位免费呈上200兆SVN代码服务器一枚,不谢! 开篇先给大家讲个我自己的故事,几个月前在网上接了个小软件开发的私活,平日上班时间也比较忙,就中午一会儿休息时间能抽出来倒腾着去做 ...
- C语言变参函数的编写
1. 引言 一般我们编程的时候,函数中形式参数的数目通常是确定的,在调用时要依次给出与形式参数对应的实际参数.但在某些情况下我 们希望函数的参数个数可以根据需要确定,因此c语言引入可变参数函数.典型的 ...
- MVC几种传值方式
一,Model public class Course { public int Id { get; set; } public string Name { get; set; } } public ...
- PrintWriter返回值乱码问题
⑴response.setCharacterEncoding("utf-8"); ⑵response.setContentType("text/html; charset ...
- 异步执行Dos命令
//Minute const ; /// <summary> /// 执行命令行 /// </summary> /// <param name="cmdLine ...
- 编译linux内核时出错
在编译linux内核的时候使用make menuconfig 可能出现下面的错误 *** Unable to find the ncurses libraries or the*** required ...
- Arcglobe三维信息系统开发常见问题
1.SDE数据库导入GDB三维图层时,发生Z值丢失 问题描述:从GDB数据库中,将一部分mutipath图层导入到SDE数据库中.用相应的arcengine程序或Arcglobe中缩放至图功能时,发现 ...
- Cookie 操作工具类
import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet ...
- [置顶] github 出现 Permission denied (publickey)的解决
今天写了一篇博客,想push到github上的时候出现了以下错误 Permission denied (publickey). fatal: The remote end hung up unexpe ...