优先队列,水题。



#include<iostream>
#include<queue>
#include<map>
#include<cstdio>
#define MAXN 1100
using namespace std;

map<int, int> team;

int main() {
    int t, sign = 0;
    while(cin >> t&& t) {
        int n, x;
        char cmd[10];
        queue<int> q1, q2[MAXN];
        for(int i = 0; i < t; i++) {
            cin >> n;
            for(int j = 0; j < n; j++) {
                cin >> x;
                team[x] = i;
            }
        }
        cout << "Scenario #" << ++sign << endl;
        while(scanf("%s", cmd)) {
            if(cmd[0] == 'S') break;
            if(cmd[0] == 'E') {
                cin >> x;
                if(q2[team[x]].empty())
                    q1.push(team[x]);
                q2[team[x]].push(x);
            }
            if(cmd[0] == 'D') {
                cout << q2[q1.front()].front() << endl;
                q2[q1.front()].pop();
                if(q2[q1.front()].empty())
                    q1.pop();
            }
        }
        cout << endl;
    }
    return 0;
}