uva 540 Team Queue(queue与STL其他容器的综合运用)

题目链接:here

思路还是很简单的,,用map[a][i]  表示编号为a 的人在i的队伍里面,然后用队列表示每个队伍;



#include<algorithm>
#include<iostream>
#include<queue>
#include<map>
#include<string>
#include<cstdio>
using namespace std;
const int maxn = 1000+10;

int main(){
    int t;
    int x=1;
    //freopen("0.txt","r",stdin);
    while(~scanf("%d",&t)&&t)
    {
        printf("Scenario #%d\n",x++);
        map<int,int> team;
        for(int i=1;i<=t;i++){
            int n;
            scanf("%d",&n);
            while(n--){
                int a;
                scanf("%d",&a);
                team[a]=i;
            }
        }
        queue<int> q,q2[maxn];
        string s;
        while(cin>>s)
        {
            if(s[0]=='S') break;
            else if(s[0]=='E'){
                int a;
                scanf("%d",&a);
                int t=team[a];
                if(q2[t].empty()) q.push(t);
                q2[t].push(a);



            }else if(s[0]=='D'){
                int t=q.front();
                cout<<q2[t].front()<<endl;;
                q2[t].pop();
                if(q2[t].empty()) q.pop();
            }
        }
        printf("\n");
    }







    return 0;
}


posted @ 2016-09-28 16:19  hong-ll  阅读(101)  评论(0编辑  收藏  举报