J - MANAGER(2.4.5)
Crawling in process...
Crawling failed
Time Limit:1000MS
Memory Limit:10000KB 64bit IO Format:%I64d & %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
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXn = 10010; bool cmp(int a, int b)
{
return a < b;
} int main()
{
int n, m, i, j, k, l, p, rmovList[MAXn], curList[MAXn], rmovNum[MAXn];
char cmd;
while (cin >> n >> m)
{
for (i = 0; i < m; i++)
cin >> rmovNum[i];
memset(curList, 0, sizeof(curList));
p = 1;
j = 1;
k = 1;
while (1)
{
cin >> cmd;
if (cmd == 'e')
break;
else if (cmd == 'a')
{
cin >> curList[j];
sort(curList + 1, curList + j + 1, cmp);
j++;
continue;
}
else if (cmd == 'r')
{
if (p == 1)
{
rmovList[k] = curList[1];
for (l = 2; l < j; l++)
curList[l-1] = curList[l];
k++;
j--;
continue;
}
else if (p == 2)
{
rmovList[k] = curList[j-1];
j--;
k++;
continue;
}
}
else if (cmd == 'p')
cin >> p;
}
for (i = 0; i < m; i++)
{
if(rmovNum[i] > k - 1)
cout << -1 << endl;
else
cout << rmovList[rmovNum[i]] << endl;
}
cout << endl;
} return 0;
}
J - MANAGER(2.4.5)的更多相关文章
- python运维开发(十一)----线程、进程、协程
内容目录: 线程 基本使用 线程锁 自定义线程池 进程 基本使用 进程锁 进程数据共享 进程池 协程 线程 线程使用的两种方式,一种为我们直接调用thread模块上的方法,另一种我们自定义方式 方式一 ...
- server服务器信息页面添加步骤
1. 在数据库更新链接 /portal/server/getServerList 2. 写实体类 Server.java 3. 写Server.hbm.xml <?xml version=&qu ...
- Objective-C程序
创建: 2018/01/17 完成: 2018/01/19 对象(object)与信息 信息式 声明实例变量 id obj; 向对象变量发送信息 [obj msg] //这就是信息式 例: [ ...
- socket.io,io=Manager(source, opts)
原文:http://www.cnblogs.com/xiezhengcai/p/3968067.html 当我们在使用 var socket = io("ws://103.31.201.15 ...
- Lind.DDD.Manager里的3,7,15,31,63,127,255,511,1023,2047
回到目录 进制 我是一个程序猿,我喜欢简单的数字,十进制如何,数字太多,有10种数字组成,但由于它广为人知,所有使用最为广泛,人们的惯性思维培养了十进制,并说它是最容易被计算的数字,事实上,在计算机里 ...
- 主机宝(zhujibao) /a/apps/zhujibao/manager/apps/config/config.php no-password Login Vulnerabilities Based On Default cookie Verification From Default File
catalog . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 主机宝管理程序使用了CodeIgniter框架,要想在CodeIgnit ...
- 在python多进程中使用manager和Barrier
注意:Barrier是PYTHON3才有的功能,在2中无法测试. #!/usr/bin/env python # -*- coding: utf-8 -*- import multiprocessin ...
- ural 1251. Cemetery Manager
1251. Cemetery Manager Time limit: 1.0 secondMemory limit: 64 MB There is a tradition at the USU cha ...
- Cloudera Manager 5和CDH5离线安装
CDH (Cloudera’s Distribution, including Apache Hadoop),是Hadoop众多分支中的一种,由Cloudera维护,基于稳定版本的Apache Had ...
随机推荐
- vmware虚拟机环境下配置centos为静态IP的步骤
一.修改centos配置文件 配置文件位于/etc/sysconfig/network-scripts/ifcfg-eth0 修改的内容为: ONBOOT=yes BOOTPROTO=static I ...
- javascript验证QQ号、邮箱和手机号码
//验证QQ号码5-11位 function isQQ(qq) { var filter = /^\s*[.0-9]{5,11}\s*$/; if (!filter.test(qq)) { retur ...
- 002_ASP.NET 换主题
网盘下载地址 http://pan.baidu.com/s/1c1VzIla 在线观看地址 http://www.bamn.cn/course/lesson/2 课程介绍 ASP.NET 实现更换主题 ...
- 【SqlServer】SqlServer的异常处理
在SQLserver数据库中,如果有很多存储过程的时候,我们会使用动态SQL进行存储过程调用存储过程,这时候,很可能在某个环节就出错了,但是出错了我们很难去跟踪到出错的存储过程,此时我们就可以使用异常 ...
- 通过nginx中转获取不到IP的问题解决
第一步:在nginx.conf中配置反向代理时把真实IP带上,例如: server { listen 80; server_name myibook.com.cn; loca ...
- 我要搬家到csdn,大家到那里来看我吧,平台更大,看到的人更多!
ruby代码 #encoding: utf-8 require 'net/http' require 'open-uri' require 'nokogiri' # 用于解析html的模块 # sud ...
- 译: 5. RabbitMQ Spring AMQP 之 Topic 主题
在上一个教程中,我们提高了消息传递的灵活 我们使用direct交换而不是使用仅能够进行虚拟广播的fanout交换, 并且获得了基于路由key 有选择地接收消息的可能性. 虽然使用direct 交换改进 ...
- DIOCP-V5发布
DIOCP-v5开源项目 https://github.com/ymofen/diocp-v5 DIOCP-v5 0.0.1 2015-02-22 08:40:40 1.规范单元文件的命名,和 ...
- Django基础学习之Cookie 和 Sessions 应用
在Django里面,使用Cookie和Session看起来好像是一样的,使用的方式都是request.COOKIES[XXX]和request.session[XXX],其中XXX是您想要取得的东西的 ...
- 批处理命令学习笔记——Start命令
Start 命令 启动另一个窗口运行指定的程序或命令,所有的DOS命令和命令行程序都可以由start命令来调用. 语法:START ["title"] [/Dpath] [/I] ...