这个题又展示了queue:
整体思路:
输入的编号用map映射到团队编号中,在然后就是输入命令:
入队命令:
用 t 记录输入x的团队编号,在q2[t]找到x团队内,如果是空的话,就把整个团队加入到整个队列中,然后再把x加入到x团队中!
出队命令:
先用t记录队首的团队编号,在把队首的团队(q2[t])的队首去掉,如果该团队为空,则把整个团队去掉,依次类推。。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#include<cstdio> #include<map> #include<queue> using namespace std; int main() { int T,cont = 0; const int maxt = 1000 + 10; while(~scanf("%d",&T) && T){ printf("Scenario #%dn",++cont); 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[maxt]; for(;;){ char cmd[10]; scanf("%s",cmd); if (cmd[0] == 'S')break; if (cmd[0] == 'E'){ int x; scanf("%d",&x); int t = team[x]; if (q2[t].empty())q.push(t); q2[t].push(x); } if (cmd[0] == 'D'){ int t = q.front(); printf("%dn",q2[t].front()); q2[t].pop(); if (q2[t].empty())q.pop(); } } printf("n"); } return 0; }
最后
以上就是自信蜻蜓最近收集整理的关于例题5-6 UVA 540 Team Queue团体队列的全部内容,更多相关例题5-6内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复