• 团体队列 UVA540 Team Queue


    题目描述

    有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在排队,那么新人会插队到最后一个队友的身后。如果没有任何一个队友排队,则他会被排到长队的队尾。

    输入每个团队中所有队员的编号,要求支持如下3中指令:

    ENQUEUE x:编号为x的人进入长队

    DEQUEUE:长队的队首出队

    STOP:停止模拟

    对于每个DEQUEUE指令,输出出队的人的编号

    样例输入

    2
    3 101 102 103
    3 201 202 203
    ENQUEUE 101
    ENQUEUE 201
    ENQUEUE
    102
    ENQUEUE 202
    ENQUEUE 103
    ENQUEUE
    203
    DEQUEUE
    DEQUEUE
    DEQUEUE
    DEQUEUE
    DEQUEUE
    DEQUEUE
    STOP
    2
    5
    259001 259002 259003 259004 259005
    6 260001 260002 260003 260004 260005
    260006
    ENQUEUE 259001
    ENQUEUE 260001
    ENQUEUE 259002
    ENQUEUE
    259003
    ENQUEUE 259004
    ENQUEUE 259005
    DEQUEUE
    DEQUEUE
    ENQUEUE
    260002
    ENQUEUE
    260003
    DEQUEUE
    DEQUEUE
    DEQUEUE
    DEQUEUE
    STOP
    0

    样例输出

    Scenario #1
    101
    102
    103
    201
    202
    203
    Scenario #2
    259001
    259002
    259003
    259004
    259005
    260001

    #define LOCAL
    #include<iostream>
    #include<cstdio>
    #include<map>
    #include<queue>
    #include<string>
    
    using namespace std;
    
    const int maxn=100;
    
    int main(){
        #ifdef LOCAL
        freopen("data.in","r",stdin);
        freopen("data.out","w",stdout);
        #endif
    
        //!1.记录所有人的团队编号,从0开始
        int t;//共有t个团队
        int kase=0;
        while(scanf("%d",&t) == 1 && t>0){
            map<int,int> team;
            cout<<"Scenario #"<<++kase<<endl;
            for(int i=0;i<t;i++){//第i个团队
                //有n个人
                int n;
                cin>>n;
                int code;
                while(n--){scanf("%d",&code);team[code]=i;}
            }
    
            //!2.模拟
            queue<int> q,q2[maxn];
            while(1){
                int x;
                string cmd;
                cin>>cmd;
                if(cmd[0] == 'S')break;
                else if(cmd[0] == 'D'){
                    x=q.front();
                    cout<<q2[x].front()<<endl;
                    q2[x].pop();
                    if(q2[x].empty())q.pop();
                }
                else if(cmd[0] == 'E'){
                    cin>>x;
                    int t=team[x];
                    if(q2[t].empty())q.push(t);
                    q2[t].push(x);
                }
            }
            cout<<endl;
        }
        return 0;
    }
    
    
    keep going
  • 相关阅读:
    Spring缓存注解@Cache使用
    Java中BigDecimal的8种舍入模式
    mysql和oracle的mybatis操作
    MyEclipse开发JAX-RS架构WebServices收发JSON数据格式
    Hibernate 常见异常
    SQL笔试题
    Map按键排序(sort by key)
    Spring+Mybatis常见问题随笔
    md5utils
    Http请求中Content-Type讲解以及在Spring MVC中的应用
  • 原文地址:https://www.cnblogs.com/MarkKobs-blog/p/10459979.html
Copyright © 2020-2023  润新知