POJ 1281 MANAGER
& %I64u
Description
The manager keeps a trace of client processes. Each process is identified by its cost that is a strictly positive integer in the range 1 .. 10000. The number of processes with the same cost cannot exceed 10000. The queue is managed according to three types
of requests, as follows:
- a x - add to the queue the process with the cost x;
- r - remove a process, if possible, from the queue according to the current manager policy;
- p i - enforce the policy i of the manager, where i is 1 or 2. The default manager policy is 1
- e - ends the list of requests.
There are two manager policies:
- 1 - remove the minimum cost process
- 2 - remove the maximum cost process
The manager will print the cost of a removed process only if the ordinal number of the removed process is in the removal list.
Your job is to write a program that simulates the manager process.
Input
- the maximum cost of the processes
- the length of the removal list
- the removal list - the list of ordinal numbers of the removed processes that will be displayed; for example 1 4 means that the cost of the first and fourth removed processes will be displayed
- the list of requests each on a separate line.
Each data set ends with an e request. The data sets are separated by empty lines.
Output
prints -1. The results are printed on separate lines. An empty line separates the results of different data sets.
An example is given in the following:
Sample Input
5
2
1 3
a 2
a 3
r
a 4
p 2
r
a 5
r
e
Sample Output
2
5
题目大意:
线程模拟。
ax——将一个花费为x的进程加到队列中
r——假设可能。依照当前管理者的策略,删除一个进程
p i ——运行管理者的策略i。当中i是1或者2。缺省值为1
e——请求列表终止
两个管理者的策略为:
1——删除最小耗费进程
2——删除最大耗费进程
输出指定的删除序列
#include <iostream>
#include<algorithm>
using namespace std;
int cmp1(int a,int b)
{
return a>b;
}
int cmp2(int a,int b)
{
return a<b;
}
int main()
{ int num;
while(cin>>num&&num)
{
int p=1;
int n;
cin>>n;
int a[1010]={0},b[1010]={0},c[2010]={0};
int i;
for(i=1;i<=n;i++)
cin>>b[i];
int a1=1,b1=1,c1=1;
char ch;
i=0;
while(cin>>ch&&ch!='e')
{
if(ch=='a')
{
cin>>a[a1];
a1++;
}
if(ch=='p')
cin>>p;
if(ch=='r')
{
if(p==1)//删除最小进程
{
sort(a+1,a+a1,cmp1);
c[c1]=a[a1-1];
c1++;
a1=a1-1;
}
if(p==2)//删除最大进程
{
sort(a+1,a+a1,cmp2);
c[c1]=a[a1-1];
c1++;
a1=a1-1;
}
}
}
for(i=1;i<=n;i++)
cout<<c[b[i]]<<endl;
cout<<endl;
}
return 0;
} /*
5
2
1 3
a 2
a 3
r
a 4
p 2
r
a 5
r
e
*/
刚開始提交WrongAnswer 后来注意到时sort函数的使用,数组開始下标从0開始还是从1開始sort括号中的的列表不同,
sort(a+1,a+a1,cmp1);
我的下标从1開始。
sort函数详情见http://blog.csdn.net/sunshumin/article/details/37756027
再提交时是PE错误,改成一次while循环加一个空行。ac。
POJ 1281 MANAGER的更多相关文章
- POJ 题目分类(转载)
Log 2016-3-21 网上找的POJ分类,来源已经不清楚了.百度能百度到一大把.贴一份在博客上,鞭策自己刷题,不能偷懒!! 初期: 一.基本算法: (1)枚举. (poj1753,poj2965 ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- POJ题目分类(转)
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- POJ题目(转)
http://www.cnblogs.com/kuangbin/archive/2011/07/29/2120667.html 初期:一.基本算法: (1)枚举. (poj1753,poj29 ...
- [POJ题目分类][转]
Hint:补补基础... 初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治 ...
随机推荐
- NAS配置Time Machine,在D-Link DNS-320上的配置笔记
今天打算把Time Machine备份的工作交给NAS,曾经是放在一块外置硬盘上的,尽管速度要比NAS快,可是每次插拔外接都有些麻烦.而NAS又具有实时在线.定时关机启动的功能.配合Time Mach ...
- Docker Compose + Spring Boot + Nginx + Mysql
Docker Compose + Spring Boot + Nginx + Mysql 实践 我知道大家这段时间看了我写关于 docker 相关的几篇文章,不疼不痒的,仍然没有感受 docker 的 ...
- React中多行文本省略不生效原因
在普通的前端项目中,在不考虑兼容问题的时候,可以用以下代码实现: overflow : hidden; text-overflow: ellipsis; display: -webkit-box; - ...
- 29.QT主窗口加widget
运行效果 widget布局showwidget.h #ifndef SHOWWIDGET_H #define SHOWWIDGET_H #include <QWidget> #includ ...
- 7个好用的在线YouTube视频下载工具
title: 7个好用的在线YouTube视频下载工具 toc: false date: 2018-10-10 15:11:00 categories: methods tags: youtube C ...
- QlikSense系列(1)——整体介绍
接触QlikSense(3.1 SR1)已经快一年了,在此记录自己的经验心得,为想了解QlikSense的小伙伴提供一个参考. 1.产品介绍 Qlik公司以QlikView产品成名,QlikSense ...
- SQL*PLUS命令的使用大全
Oracle的sql*plus是与oracle进行交互的客户端工具.在sql*plus中,可以运行sql*plus命令与sql*plus语句. 我们通常所说的DML.DDL.DCL语句都是sql*pl ...
- React实现单例组件
问题背景 在工作中遇到了这样一个场景,写了个通用的弹窗组件,却在同一个页面中多次使用了该组件.当点击打开弹窗时,可想而知,一次性打开了多个弹窗,而业务需求只需要打开一个. 我个人在解决问题过程中的一些 ...
- JSON是什么?为JavaScript准备的数据格式
JSON是什么?为JavaScript准备的数据格式 还不了解JSON是什么?看了下面这篇文章,您对JSON是什么应该能够有了一个比较清晰的概念. JSON 即 JavaScript. Object ...
- CorelDRAW 2018新增功能介绍
2018年4月11日,CorelDRAW 2018正式对外发布,最新版设计软件包已经过全面更新,是近几年来发行的最强大版本,可协助绘图专业人士将创意转换为令人惊艳的专业视觉设计.CorelDRAW 2 ...