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)递归和分治 ...
随机推荐
- [叁]Pomelo游戏server编程分享 之 server结构与配置分析
网络部署结构 我们先看一下Pomeloserver网络部署情况,直接上图 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3RiaW56aQ==/font/ ...
- 验证DG最大性能模式下使用ARCH/LGWR及STANDBY LOG的不同情况
总结: --两台单实例数据库做DG,数据库版本号10.2.0.1.0 1.主库配置为:arch async,备库无STANDBY LOG. 日志中会有:RFS[4]: No standby redo ...
- Create a Visual C++ Wizard for Visual Studio 2005
from:http://www.codeguru.com/cpp/v-s/devstudio_macros/customappwizards/article.php/c12775/Create-a-V ...
- c/c++ 比较好的开源框架
作者:EZLippi链接:https://www.zhihu.com/question/19823234/answer/31632919来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转 ...
- 求包含每个有序数组(共k个)至少一个元素的最小区间
title: 求包含每个有序数组(共k个)至少一个元素的最小区间 toc: false date: 2018-09-22 21:03:22 categories: OJ tags: 归并 给定k个有序 ...
- MVC、控件、一般处理程序中的session and cookie
Mvc中: session: if (!string .IsNullOrEmpty(find)) //设置 Session["oip"] = "无锡"; Vie ...
- GIT 常用方法
代码提交顺序: conmmit(提交代码到本地仓库) --->>> pull(将本地仓库代码合并) ---->>> push(将本地合并后的代码提交到 ...
- git提交不用每次都输入用户名密码
克隆项目二种方式: 1. 使用https url克隆, 复制https url 然后到 git clone https-url 2.使用 SSH url 克隆却需要在克隆之前先配置和添加好 SSH ...
- 记一次mybatis<if>标签的问题
前言 到底还是没理解清楚的锅~~~~搞了好久...啊啊啊啊 错误: There is no getter for property named 'name' in 'class java.lang.L ...
- BZOJ 2754 [SCOI2012]喵星球上的点名 (AC自动机+map维护Trie树)
题目大意:略 由于字符集大,要用map维护Trie树 并不能用AC自动机的Trie图优化,不然内存会炸 所以我用AC自动机暴跳fail水过的 显然根据喵星人建AC自动机是不行的,所以要根据问题建 然而 ...