题目链接:

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. POJ 3276 Face The Right Way 翻转(开关问题)

    题目:Click here 题意:n头牛排成一列,F表示牛面朝前方,B表示面朝后方,每次转向K头连续的牛的朝向,求让所有的牛都能面向前方需要的最少的操作次数M和对应的最小的K. 分析:一个区间反转偶数 ...

  2. c++,static 静态成员变量 / 静态成员函数

    静态成员变量: //静态成员变量(static) // //1.如果想在同类的多个对象之间实现数据共享 ,可以用静态 //成员变量,即用static修饰的成员变量,例 static int a; // ...

  3. 百度SiteApp构建网站APP

    现在很多个人网站和企业网站都是传统的Web方式,有没有想过个人/企业网站也能做成APP应用对外宣传呢?专门找人去开发Android和IOS上的APP又太贵,为了赶上移动互联网时髦,我以个人网站试做了一 ...

  4. zabbix 邮件告警配置

    使用外部邮箱账号发送报警邮件设置 一.关闭sendmail或者postfix service sendmail stop #关闭 chkconfig sendmail off #禁止开机启动 serv ...

  5. 多玩YY聊天记录解析全过程

    再来一发,现在开始! 下载安装YY,观察YY目录,很明显的发现了sqlite3.dll,这个数据库很多很多很多软件都在用,简单小巧且开源.删除sqlite3.dll 进入YY,历史记录不能正常显示,基 ...

  6. 基于visual Studio2013解决C语言竞赛题之0524职工年龄

     题目

  7. Bad Hair Day(单调栈 )

    Bad Hair Day Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 15941   Accepted: 5382 Des ...

  8. 疯牛-- Aggressive cows (二分)

    疯牛 时间限制:1000 ms  |  内存限制:65535 KB 难度:4   描述 农夫 John 建造了一座很长的畜栏,它包括N (2 <= N <= 100,000)个隔间,这些小 ...

  9. Android中的Audio播放:控制Audio输出通道切换

    Audio 输出通道有很多,Speaker.headset.bluetooth A2DP等.通话或播放音乐等使用Audio输出过程中,可能发生Audio输出通道的切换.比如,插入有线耳机播放音乐时,声 ...

  10. jQuery 简单滑动轮播图效果

    一般页面简单轮播图效果用jQuery制作更加简单.我们来看看以下效果是如何来进行制作的. 其html结构下所示: <div id="box">         < ...