我是靠谱客的博主 幸福刺猬,这篇文章主要介绍团体队列 UVA540 Team Queue,现在分享给大家,希望可以做个参考。

题目描述

有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在排队,那么新人会插队到最后一个队友的身后。如果没有任何一个队友排队,则他会被排到长队的队尾。

输入每个团队中所有队员的编号,要求支持如下3中指令:

ENQUEUE x:编号为x的人进入长队

DEQUEUE:长队的队首出队

STOP:停止模拟

对于每个DEQUEUE指令,输出出队的人的编号

样例输入

2
3 101 102 103
3 201 202 203
ENQUEUE 101
ENQUEUE 201
ENQUEUE
102
ENQUEUE 202
ENQUEUE 103
ENQUEUE
203
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
2
5
259001 259002 259003 259004 259005
6 260001 260002 260003 260004 260005
260006
ENQUEUE 259001
ENQUEUE 260001
ENQUEUE 259002
ENQUEUE
259003
ENQUEUE 259004
ENQUEUE 259005
DEQUEUE
DEQUEUE
ENQUEUE
260002
ENQUEUE
260003
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
0

样例输出

Scenario #1
101
102
103
201
202
203
Scenario #2
259001
259002
259003
259004
259005
260001

复制代码
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
#define LOCAL #include<iostream> #include<cstdio> #include<map> #include<queue> #include<string> using namespace std; const int maxn=100; int main(){ #ifdef LOCAL freopen("data.in","r",stdin); freopen("data.out","w",stdout); #endif //!1.记录所有人的团队编号,从0开始 int t;//共有t个团队 int kase=0; while(scanf("%d",&t) == 1 && t>0){ map<int,int> team; cout<<"Scenario #"<<++kase<<endl; for(int i=0;i<t;i++){//第i个团队 //有n个人 int n; cin>>n; int code; while(n--){scanf("%d",&code);team[code]=i;} } //!2.模拟 queue<int> q,q2[maxn]; while(1){ int x; string cmd; cin>>cmd; if(cmd[0] == 'S')break; else if(cmd[0] == 'D'){ x=q.front(); cout<<q2[x].front()<<endl; q2[x].pop(); if(q2[x].empty())q.pop(); } else if(cmd[0] == 'E'){ cin>>x; int t=team[x]; if(q2[t].empty())q.push(t); q2[t].push(x); } } cout<<endl; } return 0; }

转载于:https://www.cnblogs.com/MarkKobs-blog/p/10459979.html

最后

以上就是幸福刺猬最近收集整理的关于团体队列 UVA540 Team Queue的全部内容,更多相关团体队列内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部