题目链接:

PKU:http://poj.org/problem?id=3481

HDU:http://acm.hdu.edu.cn/showproblem.php?pid=1908

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

Source


题意:

三个操作:

1、插入两个数,第一个数是客户的名字,第二个数是优先级!

2、输出当前客户中优先级最高的名字,并删除!

3、输出当前客户中优先级最低的名字,并删除!

代码例如以下:

#include <cstdio>
#include <map>
#include <cstring>
#include <algorithm>
using namespace std;
#include <string>
map<int,int> m;
int main()
{
int op;
int name, p;
while(~scanf("%d",&op))
{
if(op == 0)
break;
if(op == 2 && m.size() == 0)
{
printf("0\n");
continue;
}
if(op == 3 && m.size() == 0)
{
printf("0\n");
continue;
}
if(op == 1)
{
scanf("%d%d",&name,&p);
m[p] = name;
continue;
}
if(op == 2)
{
printf("%d\n",(*m.rbegin()).second);
m.erase(m.find((*m.rbegin()).first));
//printf("%d\n",(*m.end()).second);
//m.erase(m.end());
//注意此处不能用*m.end(),由于*m.end()返回的是数组的最后一个单元+1的指针
}
else
{
//printf("%d\n",(*m.rend()).second);//相同
//m.erase(m.find((*m.rend()).first));
printf("%d\n",(*m.begin()).second);
m.erase(m.begin());
}
}
return 0;
}

POJ 3481 &amp; HDU 1908 Double Queue (map运用)的更多相关文章

  1. hdu 1908 Double Queue

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

  2. HDU 1908 Double Queue(set)

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

  3. 【HDOJ】1908 Double Queue

    双端队列+二分. #include <cstdio> #define MAXN 1000005 typedef struct { int id; int p; } node_st; nod ...

  4. POJ 3481 Double Queue STLmap和set新学到的一点用法

    2013-08-08 POJ 3481  Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...

  5. POJ 3481 Double Queue(Treap模板题)

    Double Queue Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15786   Accepted: 6998 Des ...

  6. POJ 3481 Double Queue(STL)

    题意  模拟银行的排队系统  有三种操作  1-加入优先级为p 编号为k的人到队列  2-服务当前优先级最大的   3-服务当前优先级最小的  0-退出系统 能够用stl中的map   由于map本身 ...

  7. POJ 3481 Double Queue(set实现)

    Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Buchares ...

  8. poj 3841 Double Queue (AVL树入门)

    /****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...

  9. 【Map】Double Queue

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

随机推荐

  1. 【QT相关】对话框相关

    为行编辑器限制规则: QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}"); lineEdit->setValidator(new QRegEx ...

  2. C语言深度剖析---预处理(define)(转载)

    1.数值宏常量     #define宏定义是个演技非常高超的替身演员,但也会耍大牌的,所以我们使用它要慎之又慎.它可以出现在代码的任何地方,从本行宏定义开始,以后的代码都认识宏了:也可以把任何东西都 ...

  3. 动态加载EXE和DLL

    程序中加载了一个DLL文件,但生成的EXE在脱离了DLL文件后仍然可以 单独使用,这是动态加载DLL技术.即:调用资源中的DLL. 此技术的好处:EXE可以使用DLL中的函数,但不会额外增加一 个DL ...

  4. python _thread模块使用

    python关于线程管理的有2个类,_thread(在2.x的版本中叫thread)和threading. # encoding: UTF-8 import thread import time   ...

  5. 期权put和call

    今天和朋友谈到了FB的期权操作问题,保证一个固定收益或者得到一个以低价买入FB的机会. 首先说下基本概念:call:是指买权put :是指卖权但是这两种期权又分别对应了long和short的两种操作, ...

  6. location.href使用方法总结

    javascript中的location.href有非常多种使用方法,主要例如以下. self.location.href="/url" 当前页面打开URL页面 location. ...

  7. SuperSocket源码解析之启动过程

    一 简介 这里主要说明从配置系统引导启动SuperScoekt作为应用程序,且以控制台程序方式启动 二 启动过程 2.1 配置解析 从读取配置文件开始,直接拿到一个SocketServiceConfi ...

  8. [置顶] ssize_t与size_t-linux

    ssize_t: signed size_t [注释:signed 有符号] size_t: 标准C库中定义的,应为unsigned int [注释:unsigned 无符号] 一.size_t 增强 ...

  9. date、datetime、string的相互转换

    import datetime import time string转datetime str = '2012-11-19' date_time = datetime.datetime.strptim ...

  10. opencv实现连通域

    在本文中使用图像连通域统计使用opencv中的cvFloodFill方法,可是在cvFloodFill方法中CvConnectedComp參数无法返回详细点坐标位置信息,找了些资料.给CvSeq分配空 ...