我是靠谱客的博主 壮观柜子,这篇文章主要介绍Uva - 540 - Team Queue,现在分享给大家,希望可以做个参考。



用两个队列,每个团队有一个队列,包含自己队伍中的人员编号,而团队整体形成一个队列,包含队列中的团队编号。

AC代码:

复制代码
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set> #include <map> #include <algorithm> #include <stack> #include <queue> using namespace std; const int maxt = 1010; int main() { int t, kase = 0; while (scanf("%d", &t) == 1 && t) { printf("Scenario #%dn", ++kase); map<int, int> team; // team[x]表示编号为x的人所在的团队编号 for (int i = 0; i < t; i++) { int n, x; scanf("%d", &n); while (n--) { scanf("%d", &x); team[x] = i; } } queue<int> qt, qp[maxt]; // qt是团队的队列,qp[i]是团队i成员队列 while (1) { char cmd[10]; scanf("%s", cmd); if (cmd[0] == 'S') { break; } else if (cmd[0] == 'E') { int x; scanf("%d", &x); int t = team[x]; if (qp[t].empty()) { // 如果x所在的团队没有人在团队队列中,团队t入列 qt.push(t); } qp[t].push(x); } else { int t = qt.front(); printf("%dn", qp[t].front()); qp[t].pop(); if (qp[t].empty()) { qt.pop(); // 如果某个人出队后,队伍空了 // 那就把队伍从队伍队列中出列 } } } printf("n"); } return 0; }




转载于:https://www.cnblogs.com/zhangyaoqi/p/4591594.html

最后

以上就是壮观柜子最近收集整理的关于Uva - 540 - Team Queue的全部内容,更多相关Uva内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(77)

评论列表共有 0 条评论

立即
投稿
返回
顶部