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 ...
随机推荐
- goahead cgi 及出现的问题解决
1. route.txt 配置cgi路径 route uri=/cgi-bin dir=/web handler=cgi 2.交叉编译生成cgi goahead 源码路径下 ./test/c ...
- javascript 学习随笔6
改变html内容 document.getElementById("p1").innerHTML="New text!"; var element=docume ...
- FileDescriptor
FileDescriptor 在java中的java.io包下面 public final class FileDescriptor { ... } 官方的解释: 文件描述符类的实例用作与基础机器有关 ...
- Qt对话框_模态/非模态
对话框在Qt GUI应用程序中有着广泛的用途,对话框有模态.非模态两种情况. 对于参数选择的对话框,一般用模态对话框:对于显示或查看某些内容的对话框,一般用非模态对话框. 对话框类QDialog,官方 ...
- Delphi启动/停止Windows服务,启动类型修改为"自动"
unit U_StartServices; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Contr ...
- QT全平台设置图标,全平台静态编译 good
1. 概述 当我们用QT写好了一个软件,要把你的程序分享出去的时候,不可能把编译的目录拷贝给别人去运行.编译好的程序应该是一个主程序,加一些资源文件,再加一些动态链接库,高大上一些的还可以做一个安装 ...
- 基于visual Studio2013解决C语言竞赛题之0603打印素数
题目
- Ruby学习-第一章
第一章 字符串,数字,类和对象 为了证明Ruby真的好用,hello world也能写的如此简洁: puts 'hello world' 1.输入/输出 print('Enter your name' ...
- 亚马逊带Marketplace product code的image无法再mount到其他镜像上
这是对已发布镜像的保护么?难道对其进行修改的路彻底断掉了? 以volume形式attach也不行,dd成raw再读取也读不了,敢问路在何方呢 If a volume has an AWS Market ...
- 富文本编辑器 - wangEditor 上传图片
效果: . 项目结构图: wangEditor-upload-img.html代码: <html> <head> <title>wangEditor-图片上传< ...