AcWing 132. 그룹 대기 열 (양단 대기 열 운용)

전송 문
한 대열 로 현재 대열 에 있 는 팀 의 선후 순 서 를 저장 한 다음 에 한 대열 로 각 팀 의 선후 순 서 를 저장 하 는 것 은 정말 기묘 하 다.
#include 

using namespace std;
const int MAXN = 1e6 + 10;
deque<int> P[1010], Q;
int t, n, tmp, Group[MAXN];
string s;

int main() {
    //freopen("in", "r", stdin);
    ios::sync_with_stdio(false);
    int Case = 0;
    while (cin >> t && t) {
        for (int i = 0; i < t; i++) {
            P[i].clear();
            Group[i] = 0;
        }
        Q.clear();
        for (int Cas = 1; Cas <= t; Cas++) {
            cin >> n;
            for (int i = 1; i <= n; i++) {
                cin >> tmp;
                Group[tmp] = Cas;
            }
        }
        cout << "Scenario #" << ++Case << endl;
        while (cin >> s) {
            if (s[0] == 'S')
                break;
            if (s[0] == 'E') {
                cin >> tmp;
                if (!P[Group[tmp]].size())
                    Q.push_back(Group[tmp]);
                P[Group[tmp]].push_back(tmp);
            } else if (s[0] == 'D') {
                int top = Q.front();
                cout << P[top].front() << endl;
                P[top].pop_front();
                if (!P[top].size())
                    Q.pop_front();
            }
        }
        cout << endl;
    }
    return 0;
}

좋은 웹페이지 즐겨찾기