J - MANAGER(2.4.5)

Crawling in process...
Crawling failed
Time Limit:1000MS    
Memory Limit:10000KB     64bit IO Format:%I64d & %I64u

Description

One of the programming paradigm in parallel processing is the producer/consumer paradigm that can be implemented using a system with a "manager" process and several "client" processes. The clients can be producers, consumers, etc.
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 input is from the standard input. Each data set in the input has the following format:

  • 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

The program prints on standard output the cost of each process that is removed, provided that the ordinal number of the remove request is in the list and the queue is not empty at that moment. If the queue is empty the program
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)的更多相关文章

  1. python运维开发(十一)----线程、进程、协程

    内容目录: 线程 基本使用 线程锁 自定义线程池 进程 基本使用 进程锁 进程数据共享 进程池 协程 线程 线程使用的两种方式,一种为我们直接调用thread模块上的方法,另一种我们自定义方式 方式一 ...

  2. server服务器信息页面添加步骤

    1. 在数据库更新链接 /portal/server/getServerList 2. 写实体类 Server.java 3. 写Server.hbm.xml <?xml version=&qu ...

  3. Objective-C程序

    创建: 2018/01/17 完成: 2018/01/19  对象(object)与信息  信息式 声明实例变量  id obj;  向对象变量发送信息 [obj msg] //这就是信息式 例: [ ...

  4. socket.io,io=Manager(source, opts)

    原文:http://www.cnblogs.com/xiezhengcai/p/3968067.html 当我们在使用 var socket = io("ws://103.31.201.15 ...

  5. Lind.DDD.Manager里的3,7,15,31,63,127,255,511,1023,2047

    回到目录 进制 我是一个程序猿,我喜欢简单的数字,十进制如何,数字太多,有10种数字组成,但由于它广为人知,所有使用最为广泛,人们的惯性思维培养了十进制,并说它是最容易被计算的数字,事实上,在计算机里 ...

  6. 主机宝(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 ...

  7. 在python多进程中使用manager和Barrier

    注意:Barrier是PYTHON3才有的功能,在2中无法测试. #!/usr/bin/env python # -*- coding: utf-8 -*- import multiprocessin ...

  8. ural 1251. Cemetery Manager

    1251. Cemetery Manager Time limit: 1.0 secondMemory limit: 64 MB There is a tradition at the USU cha ...

  9. Cloudera Manager 5和CDH5离线安装

    CDH (Cloudera’s Distribution, including Apache Hadoop),是Hadoop众多分支中的一种,由Cloudera维护,基于稳定版本的Apache Had ...

随机推荐

  1. SpringBoot中配置起动时的数据库初始化角本

    一.简介 我们使用SpringBoot + JPA时,需要程序在启动时执行数据表的初始化或者数据库记录的初始化.一般数据表的初始化可以通过在Spring Boot的application.proper ...

  2. 在SpringBoot中使用热部署(DevTools)

    一.简介 有时候我们开发完SpringBoot项目后,启动运行.但是经常发现代码需要反复修改,然后修改部分内容后需要再启动....这样太费时了,热部署就是用来解决这一问题.让你修改完代码后,能自动执行 ...

  3. mock以及特殊场景下对mock数据的处理

    一.为什么要mock 工作中遇到以下问题,我们可以使用mock解决: 无法控制第三方系统某接口的返回,返回的数据不满足要求 某依赖系统还未开发完成,就需要对被测系统进行测试 有些系统不支持重复请求,或 ...

  4. 转 qInstallMsgHandler实现日志输出

    #include <QtDebug> #include <QFile> #include <QTextStream> #define _TIME_ qPrintab ...

  5. 【LeetCode】238. Product of Array Except Self

    Product of Array Except Self Given an array of n integers where n > 1, nums, return an array outp ...

  6. 1 翻译系列:什么是Code First(EF 6 Code First 系列)

    原文链接:http://www.entityframeworktutorial.net/code-first/what-is-code-first.aspx EF 6 Code-First系列文章目录 ...

  7. SNF快速开发平台MVC-EasyUI3.9之-DataGrid表格控件如何增加右键菜单

    如题,我们在项目开发当中会遇到需要,表格控件增加右键菜单的使用. 下面我们就以SNF框架增加右键菜单步骤如下: 1.在加载页面当中增加如下菜单定义 <div id="mm" ...

  8. Socket网络编程--简单Web服务器(2)

    上一小节通过阅读开源的Web服务器--tinyhttpd.大概知道了一次交互的请求信息和应答信息的具体过程.接下来我就自己简单的实现一个Web服务器. 下面这个程序只是实现一个简单的框架出来.这次先实 ...

  9. 关于烦躁的网页编码问题utf-8,gb2312。终于自己实践了一遍

    俗话说实践是检验真理的唯一标准,的确如此. 自己一直比较懒,虽然觉得大牛应该一个记事本全部搞定,但自己还是喜欢用Dw或者Vs写好网页的架构,因为总觉得用notepad还要自己导入声明,而gVim还没有 ...

  10. GDB用法简要整理

    [时间:2017-05] [状态:Open] [关键词:gdb,调试,debug,用户手册] 使用gdb是需要在编译是指定-g命令,在可执行文件中添加符号信息. 1. 启动和退出 可以使用gdb gd ...