我是靠谱客的博主 欣喜大米,这篇文章主要介绍UVA540 Team Queue,现在分享给大家,希望可以做个参考。

链接:https://vjudge.net/problem/UVA-540

        队列是符合“先进先出”(First In First Out, FIFO)原则的“公平队列“。STL队列定义在头文件<queue>中,可以用”queue<int> s“方式声明一个队列,用push()和pop()进行元素的入队和出队操作,front()取队首元素(但不删除)。

复制代码
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
#include <iostream> #include <queue> #include <map> #include <cstdio> using namespace std; const int maxt=1000+10; 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> q,q2[maxt]; for(;;) { int x; char cmd[10]; scanf("%s",cmd); if(cmd[0]=='S') { break; } else if(cmd[0]=='D') { int t=q.front(); printf("%dn",q2[t].front()); q2[t].pop(); if(q2[t].empty())//团队t空了,全体出队列 q.pop(); } else if(cmd[0]=='E') { scanf("%d",&x); int t=team[x]; if(q2[t].empty()) q.push(t);//团队t进入队列 q2[t].push(x); } } printf("n"); } return 0; }
AC Code

本来写了一些队列的常规操作在台式机上,结果机房的交换机被人弄走了23333,现在用自己的笔记本写了这篇博客,大家可以自行查一下队列,在cplusplus上面其实讲的很清楚。

转载于:https://www.cnblogs.com/Rysort/p/9566554.html

最后

以上就是欣喜大米最近收集整理的关于UVA540 Team Queue的全部内容,更多相关UVA540内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部