题目大意:t 个队伍排队,若队伍中已经有自己队伍的人,则排到这个人的后面,若没有,排到整个队列的后面。
解题思路:模拟,映射把每个人和队伍号对应起来,定义两个队列,一个排队,另一个记录某个队伍已排人数。本来是自己写数组模拟的,TLE,看了小紫学 STL。
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctype.h>
#include<queue>
#include<map>
using namespace std;
int cnt = 0;
int main() {
int t;
while (scanf("%d", &t) != EOF && t) {
printf("Scenario #%d\n", ++cnt);
map<int, int> team;
for (int i = 0; i < t; i++) {
int n, x;
scanf("%d", &n);
while (n--) {
scanf("%d", &x);
team[x] = i;
}
}
queue<int> q, q2[1010];
char cmd[10];
while (scanf("%s", cmd) != EOF && cmd[0] != 'S') {
if (cmd[0] == 'E') {
int t, x;
scanf("%d", &x);
t = team[x];
if (q2[t].empty()) q.push(t);
q2[t].push(x);
}
else if (cmd[0] == 'D') {
int t = q.front();
printf("%d\n", q2[t].front());
q2[t].pop();
if (q2[t].empty()) q.pop();
}
}
printf("\n");
}
return 0;
}