• POJ 1281 MANAGER


    题目链接:

    http://poj.org/problem?id=1281

    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

     Hint:

    题意:

    先给出一个n,m;

    n表示这个程序最大的运行时间(虽然没什么用),再给出m,表示查询第几个删除的数字(好吧,自己语言也表达不清楚,看代码)。 

    a x—将一个花费为x的进程加到队列中

    r—如果可能,按照当前管理者的策略,删除一个进程

    p i—执行管理者的策略i,其中i是1或者2,缺省值为1

    e—请求列表终止

    两个管理者的策略为:

    1——删除最小耗费进程

    2——删除最大耗费进程

    题解:

    水题,简单的模拟即可,虽然自己也wa了好几遍。。格式比较坑。

    代码:

    #include <cmath>
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    const int maxn = 10000+10;
    #define met(a,b) memset(a,b,sizeof(a))
    int a[maxn],b[maxn],c[maxn];
    int n,m;
    int cmp1(int a,int b)
    {
        return a>b;
    }
    int cmp2(int a,int b)
    {
        return a<b;
    }
    int main()
    {
        int n,m;
        while(scanf("%d",&n)!=EOF&&n)
        {
            scanf("%d",&m);
            met(a,0); met(b, 0); met (c,0);
            for(int i=1;i<=m;i++)
                scanf("%d",& b[i]);
            char s;
            int num=1;
            int  a1=1,c1=1;
            while(scanf("%c",&s)&&s !='e')
            {
                if(s=='a')
                {
                    scanf("%d",&a[a1]);
                    a1++;
                }
                if (s=='p')
                    scanf("%d",&num);
                if(s=='r')
                {
                    if(num==1)
                    {
                        sort(a+1,a+a1,cmp1);
                        c[c1]=a[a1-1];
                        printf("%d
    ",c[c1]);
                        c1++;
                        a1-=1;
                    }
                    if(num==2)
                    {
                        sort(a+1,a+a1,cmp2);
                        c[c1]=a[a1-1];
                        c1++;
                        a1-=1;
                    }
                }
            }
           for(int  i=1;i<=m;i++)
               printf("%d
    ",c[b[i]]);
            printf("
    ");
        }
    }
    
  • 相关阅读:
    Dynamics CRM修改密码界面
    Dynamics CRM新加了组织后提示数据加密错误的解决方法
    ADFS修改默认访问端口
    Dynamics CRM与ADFS安装到同一台服务器后ADFS服务与Dynamics CRM沙盒服务冲突提示808端口占用问题
    Dynamics CRM各个版本的元数据浏览解决方案
    Dynamics CRM9.0安装CRM的时候提示Microsoft.Crm.Setup.Server.RegisterSandboxServiceAction操作失败
    IIS误删了默认网站,恢复方法
    grafana配置邮件告警
    Git连接Gitlab并提交内容
    docker自定义bridge
  • 原文地址:https://www.cnblogs.com/TAT1122/p/5826202.html
Copyright © 2020-2023  润新知