题目链接:

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. Xcode插件(一)-规范注释生成器VVDocumenter

    原文来自:http://blog.csdn.net/hitwhylz/article/details/27813315 分享几个常用的Xcode插件. 第一个, 规范注释生成器VVDocumenter ...

  2. (Problem 7)10001st prime

    By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. ...

  3. Week12(11月28日)

    Part I:提问 =========================== 1.解读以下代码 $(document).ready(function(){    $('#btn1').click(fun ...

  4. django学习之Model(四)MakingQuery

    上一篇写到MakingQuey中的filter,本篇接着来. 10)-扩展多值的关系 如果对一个ManyToManyField或ForeignKey的表进行filter过滤查询的话,有2中方法可以用. ...

  5. 1688: [Usaco2005 Open]Disease Manangement 疾病管理( 枚举 )

    我一开始写了个状压dp..然后没有滚动就MLE了... 其实这道题直接暴力就行了... 2^15枚举每个状态, 然后检查每头牛是否能被选中, 这样是O( 2^15*1000 ), 也是和dp一样的时间 ...

  6. 安装MyEclipse Color Themes

    下载地址:http://eclipsecolorthemes.org/?list=toppicks&lang=html 安装步骤如下: 1.Import---Preferences 2.选择下 ...

  7. getElementById的缩略

    谁都知道document.getElementById这个方法写起来比较麻烦,所以有时候我们会使用jq或者自己写一个小函数去封装,但是我这次说的缩略不同于往常的函数封装 在以前,我做过很多这样的尝试, ...

  8. 分享非常有用的Java程序 (关键代码) (二)---列出文件和目录

    原文:分享非常有用的Java程序 (关键代码) (二)---列出文件和目录 File dir = new File("directoryName"); String[] child ...

  9. VC实现URL编解码器

    //变化UTF8为了中国 void UTF8ToGB(CString& szstr) { WCHAR* strSrc; TCHAR* szRes; int i = MultiByteToWid ...

  10. BZOJ 3398: [Usaco2009 Feb]Bullcow 牡牛和牝牛( dp )

    水题...忘了取模就没1A了.... --------------------------------------------------------------------------- #incl ...