POJ 3481 & HDU 1908 Double Queue (map运用)
题目链接:
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 |
| 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
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 & HDU 1908 Double Queue (map运用)的更多相关文章
- hdu 1908 Double Queue
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1908 Double Queue Description The new founded Balkan ...
- HDU 1908 Double Queue(set)
Problem Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in B ...
- 【HDOJ】1908 Double Queue
双端队列+二分. #include <cstdio> #define MAXN 1000005 typedef struct { int id; int p; } node_st; nod ...
- POJ 3481 Double Queue STLmap和set新学到的一点用法
2013-08-08 POJ 3481 Double Queue 这个题应该是STL里较简单的吧,用平衡二叉树也可以做,但是自己掌握不够- -,开始想用两个优先队列,一个从大到小,一个从小到大,可是 ...
- POJ 3481 Double Queue(Treap模板题)
Double Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15786 Accepted: 6998 Des ...
- POJ 3481 Double Queue(STL)
题意 模拟银行的排队系统 有三种操作 1-加入优先级为p 编号为k的人到队列 2-服务当前优先级最大的 3-服务当前优先级最小的 0-退出系统 能够用stl中的map 由于map本身 ...
- POJ 3481 Double Queue(set实现)
Double Queue The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Buchares ...
- poj 3841 Double Queue (AVL树入门)
/****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...
- 【Map】Double Queue
Double Queue Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13258 Accepted: 5974 Des ...
随机推荐
- Linux DM9000网卡驱动程序完全分析
Linux DM9000网卡驱动程序完全分析http://blog.csdn.net/ypoflyer/article/details/6209922
- bresenham算法的FPGA的实现2
在上一篇里http://www.cnblogs.com/sepeng/p/4045593.html <bresenham算法的FPGA的实现1>已经做了一个整体框架的布局,但是那个程序只是 ...
- 浏览器hack总结 详细的浏览器兼容性解决方法
由于各浏览器对页面的解析不同,会导致页面在不同浏览器中显示的样式不一致,为了保持页面的统一,经常需要对浏览器进行兼容性问题的调试. CSS Hack 面对浏览器诸多的兼容性问题,经常需要通过CSS样式 ...
- php MySQLi部分函数(面向对象和过程)
版本支持:PHP > 5.0 MySQL > 4.0 2. mysqli 连接数据库: $db = new mysqli(host,user,password,database);返回一 ...
- Android 文件共享服务器
http://download.csdn.net/detail/liduanw/6271075 你可以将自己的手机作为(局域网)服务器, 使用方法: 1> 指定共享根目录 2> 点击启动 ...
- uva - Broken Keyboard (a.k.a. Beiju Text)(链表)
11988 - Broken Keyboard (a.k.a. Beiju Text) You’re typing a long text with a broken keyboard. Well i ...
- java序列化对象 插入、查询、更新到数据库
java序列化对象 插入.查询.更新到数据库 : 实现代码例如以下: import java.io.ByteArrayInputStream; import java.io.ByteArrayOutp ...
- AES SHA-1 SM3 MD5
AES是美国国家标准技术研究所NIST旨在代替DES的21世纪的加密标准. 输入:128bit 的消息分组 输出:128bit 的密文分组 密钥长度及圈数 128 10 192 12 256 14 消 ...
- XML 的实体引用
实体引用 在 XML 中,一些字符拥有特殊的意义. 如果你把字符 "<" 放在 XML 元素中,会发生错误,这是因为解析器会把它当作新元素的开始. 这样会产生 XML 错误: ...
- H5前端面试题及答案(2)
最近想着跳槽,但面试的邀约不多,内心有点烦躁.梳理梳理心情,跳槽季竞争也大,努力做好自己... 21.请设计一套方案,用于确保页面中js加载完全. <!doctype html> < ...