题目链接:

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

  1. 2
  2. 1 20 14
  3. 1 30 3
  4. 2
  5. 1 10 99
  6. 3
  7. 2
  8. 2
  9. 0

Sample Output

  1. 0
  2. 20
  3. 30
  4. 10
  5. 0

Source


题意:

三个操作:

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

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

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

代码例如以下:

  1. #include <cstdio>
  2. #include <map>
  3. #include <cstring>
  4. #include <algorithm>
  5. using namespace std;
  6. #include <string>
  7. map<int,int> m;
  8. int main()
  9. {
  10. int op;
  11. int name, p;
  12. while(~scanf("%d",&op))
  13. {
  14. if(op == 0)
  15. break;
  16. if(op == 2 && m.size() == 0)
  17. {
  18. printf("0\n");
  19. continue;
  20. }
  21. if(op == 3 && m.size() == 0)
  22. {
  23. printf("0\n");
  24. continue;
  25. }
  26. if(op == 1)
  27. {
  28. scanf("%d%d",&name,&p);
  29. m[p] = name;
  30. continue;
  31. }
  32. if(op == 2)
  33. {
  34. printf("%d\n",(*m.rbegin()).second);
  35. m.erase(m.find((*m.rbegin()).first));
  36. //printf("%d\n",(*m.end()).second);
  37. //m.erase(m.end());
  38. //注意此处不能用*m.end(),由于*m.end()返回的是数组的最后一个单元+1的指针
  39. }
  40. else
  41. {
  42. //printf("%d\n",(*m.rend()).second);//相同
  43. //m.erase(m.find((*m.rend()).first));
  44. printf("%d\n",(*m.begin()).second);
  45. m.erase(m.begin());
  46. }
  47. }
  48. return 0;
  49. }

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相关】QT+opencv环境配置

    在qt msvc2010版软件中使用opencv2.4.9进行库函数配置.仅适用于windows下. INCLUDEPATH += $$PWD/../../../opencv/build/includ ...

  2. Chapter 4.开放-封闭原则

    开放-封闭原则:是说软件实体应该可以扩展,但不可修改. 设计人员必须对于他设计的模块应该对哪种变化封闭做出选择,先猜测出最有可能发生的变化种类,然后构造抽象来隔离那些变化. 面对需求,对程序的改动是通 ...

  3. HTMLParser-简单HTML和XHTML解析

    使用HTMLParser模块解析HTML页面 HTMLParser是python用来解析html和xhtml文件格式的模块.它可以分析出html里面的标签.数据等等,是一种处理html的简便途径.HT ...

  4. linux下利用sed重命名文件

    3 for file in `ls ./*.*`  4 do  5 mv $file `echo $file|sed 's/IM_21R_ID331/1M21R_ID331/g'`  6 done  ...

  5. SuperSocket源码解析之开篇

    一 简介 官方介绍:SuperSocket 是一个轻量级, 跨平台而且可扩展的 .Net/Mono Socket 服务器程序框架.你无须了解如何使用 Socket, 如何维护 Socket 连接和 S ...

  6. VirtualBox开发环境的搭建详解

    有关VirtualBox的介绍请参考:VirtualBox_百度百科 由于VirtualBox官网提供的搭建方法不够详细,而且本人在它指导下,从下载所需的开发包,到最后生成二进制文件,中间遇到了许多的 ...

  7. windows下apache如何完整卸载?

    1.运行services.msc,在服务中停止 apache 服务.2.运行命令行程序,输入 sc delete apache,删除该服务3.删除apache文件夹.

  8. 重设mysql数据库root用户密码

     原文:http://blog.sina.com.cn/s/blog_a3695da601010mrs.html   1, 启用任务管理器,结束mysql进程   2,进入命令行,进入mysql的bi ...

  9. ios网络学习------1get post异步请求

    网络请求的步骤: get请求: #pragma mark - 这是私有方法,尽量不要再方法中直接使用属性,由于一般来说属性都是和界面关联的,我们能够通过參数的方式来使用属性 #pragma mark ...

  10. AdTime:多屏时代下传统媒体的鼓起

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdTAxMzk1MTQzNQ==/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...