1 #include "cstdio"
2 #include "queue"
3 #include "map"
4 using namespace std;
5 int main()
6 {
7 int t,kase=0;//t团队数目
8 while (scanf("%d",&t)==1&&t)
9 {
10 printf("Scenario #%d\n", ++kase);
11 map<int, int> team;//记录所有人团队编号
12 //<元素x,团队编号>
13 //team[x]为元素x所在团队的编号
14 for (int i = 0; i < t; i++)
15 {
16 int n;//每个团队的元素个数
17 scanf("%d", &n);
18 while (n--)
19 {
20 int x;
21 scanf("%d", &x);
22 team[x] = i;
23 }
24 }
25 queue<int> q, q2[1010];
26 while (true)
27 {
28 char cmd[10];
29 scanf("%s", cmd);
30 if (cmd[0] == 'S')//STOP
31 break;
32 else if (cmd[0] == 'D')//队首出队
33 {
34 int t = q.front();
35 printf("%d\n", q2[t].front());
36 q2[t].pop();
37 if (q2[t].empty())
38 q.pop();//团队t全部出队
39 }
40 else if (cmd[0] == 'E')//入队
41 {
42 int x;
43 scanf("%d", &x);
44 int t = team[x];
45 if (q2[t].empty())//为空加入q
46 q.push(t);
47 q2[t].push(x);
48 }
49 }
50 printf("\n");
51 }
52 return 0;
53 }
UVA 540 Team Queue
最新推荐文章于 2025-12-02 15:32:05 发布
本文介绍了一个使用C++实现的团队竞赛模拟程序。程序通过读取输入数据,模拟多个团队的竞赛过程,包括团队成员的入队和出队操作。采用map和queue数据结构来跟踪每个团队的状态,实现了竞赛的动态更新。
522

被折叠的 条评论
为什么被折叠?



