poj 3481--Double Queue
来源:互联网 发布:管家婆erp端口 编辑:程序博客网 时间:2024/04/29 04:27
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 priorityP. 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 thelowest priority instead of that with the highest priority. Thus, the system will receive the following types of request:
0The system needs to stop serving1 K PAdd client K to the waiting list with priority P2Serve the client with the highest priority and drop him or her from the waiting list3Serve the client with the lowest priority and drop him or her from the waiting listYour task is to help the software engineer of the bank by writing a program to implement the requested serving policy.
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 priorityP is less than 107. The client may arrive for being served multiple times, and each time may obtain a different priority.
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.
21 20 141 30 321 10 993220
02030100
题意: 有三种操作,1添加客户,2输出优先级最高的客户并删掉,3输出优先级最低的客户并删掉。
思路;看到题目要求,一个键值,每个键值有一个vlue,所以就想用map<int,int>解决一下,本题有好多解决方法,这里边主要用一下map、
ac代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <map>using namespace std;int main(){ map<int,int> phi; int x,a,b; while(scanf("%d",&x)&&x!=0) { if(x==1) { scanf("%d%d",&a,&b); phi[b]=a; } if(x==2) { if(phi.empty()) printf("0\n"); else { printf("%d\n",phi.rbegin()->second); phi.erase(phi.find(phi.rbegin()->first)); } } if(x==3) { if(phi.empty()) printf("0\n"); printf("%d\n",phi.begin()->second); phi.erase(phi.find(phi.begin()->first)); } } return 0;}
- poj 3481 Double Queue
- Double Queue POJ 3481
- POJ 3481 Double Queue
- POJ 3481 Double Queue
- POJ 3481 Double Queue
- POJ 3481 Double Queue
- POJ 3481 Double Queue
- poj 3481 Double Queue
- poj 3481 Double Queue
- POJ - 3481 Double Queue
- POJ 3481 Double Queue
- POJ 3481 Double queue
- POJ 3481Double Queue
- POJ--3481 Double Queue
- POJ - 3481 Double Queue
- poj 3481 Double Queue
- poj 3481--Double Queue
- POJ 3481 Double Queue
- Android_APP 常用图标尺寸规范
- access denied for user 'root'@'localhost'(using password:YES)解决方案
- 利用多线程解决生成券性能问题
- python常用模块
- 数据库结构比较工具
- poj 3481--Double Queue
- Java集合Map,set, list 之间的转换
- oracle学习总结--------oracle数据库的启动流程
- ubuntu wangka
- redis 报错
- linux命令-系统管理
- 火星人有理想有抱负,敢打敢拼
- 适配器总结
- 百度语音识别、语音合成,NAudio录音(C#)