我是靠谱客的博主 怕孤独宝贝,这篇文章主要介绍uva 540(线性表),现在分享给大家,希望可以做个参考。

题解:用一个map存储每个号码的队伍号,然后再用二维队列存放每个队伍的进场号码,最后再用一个队列存储已经在排队的队伍号,队伍空了就pop掉,下一个队伍补上。

复制代码
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
#include <cstdio> #include <cstring> #include <queue> #include <map> using namespace std; int main() { int t, n, a, cases = 1, flag; queue<int> q[1005]; queue<int> q2; char str[10]; while (scanf("%d", &t) && t) { map<int,int> m; for (int i = 1; i <= t; i++) { scanf("%d", &n); for (int j = 1; j <= n; j++) { scanf("%d", &a); m[a] = i; } } printf("Scenario #%dn", cases++); while (scanf("%s", str)) { if (str[0] == 'S') break; else if (str[0] == 'E') { scanf("%d", &a); if (q[m[a]].empty()) q2.push(m[a]); q[m[a]].push(a); } else { flag = q2.front(); printf("%dn", q[flag].front()); q[flag].pop(); if (q[flag].empty()) { q2.pop(); } } } printf("n"); for (int i = 1; i <= t; i++) while (!q[i].empty()) q[i].pop(); while (!q2.empty()) q2.pop(); } return 0; }

最后

以上就是怕孤独宝贝最近收集整理的关于uva 540(线性表)的全部内容,更多相关uva内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部