#UVA 540 Team Queue (STL map+queue)

Team Queue

题意:讲的 teamqueue 。举个例子就是若干个班级排队去中华恐龙公园玩,有俩操作。

ENQUEUE: class 3 的 stu 4 来晚了,发现自己的班级在大部队里,于是就过去排在自己班级的最后面, class 4 的 stu 6 同学来早了,发现自己的班级不在大部队,于是就排在了大部队的最后一个,所以当class4的其他同学来的时候就可以排在他后面了。

DEQUEUE:出队的时候总是大部队队首出队,当一个班级队员为空时,大部队里就没有这个班级的学生了,所以储存班级的 queue 里要出队。
分析:使用 map 来标记队员的班级的关系,使用俩队列储存班级信息和各个班级的队列信息(队列数组)。

代码如下:

#include <bits/stdc++.h>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    int t,kase=1;
    while(cin>>t && t){
        cout<< "Scenario #" << kase++ <<endl;
        map< int,int > belong_to;
        for(int i=0;i<t;i++){
            int n;
            cin>>n;
            for(int j=0;j<n;j++){
                int mem;
                cin>>mem;
                belong_to[mem] = i;
            }
        }

        string op;
        queue< int > Large_que,Little_que[1005];//前者保存团队序号 后者各团队队列<队列数组>
        while(cin>>op){
            if(op == "STOP")
                break;
            else if(op == "ENQUEUE"){
                int mem;
                cin>>mem;
                if(Little_que[ belong_to[mem] ].empty()){
                    Large_que.push( belong_to[mem] );
                }
                Little_que[ belong_to[mem] ].push( mem );
            }
            else if(op == "DEQUEUE"){
                int team = Large_que.front();
                cout<< Little_que[ team ].front() <<endl;
                Little_que[ team ].pop();
                if(Little_que[ team ].empty()){
                    Large_que.pop();//团队成员为空 队列序号出队
                }
            }
        }
        cout<<endl;
    }
    return 0;
}

JNU ACM ICPC
WYC

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值