Team Queue UVA - 540

题意:有t个团队的人正在排一个长队。每次新来一个人时,如果他有队友在队伍里,那么这个新人会插队到最后一个队友的身后;否则他就排到长队的末尾。

    ENQUEUX x: 编号为x人进入长队。

    DEQUEUX: 长队的队首出队。

    STOP: 停止模拟。

用两个队列,一个是长队,一个是各个团队的队列。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<string>
 5 #include<cstdio>
 6 #include<queue>
 7 #include<map>
 8 using namespace std;
 9
10 const int maxn=1005;
11
12 int main()
13 {   int t,T=0;
14     while(scanf("%d",&t)&&t){
15         map<int,int> text;
16         for(int i=0;i<t;i++){
17             int n,m;
18             cin>>n;
19             while(n--){
20                 cin>>m;
21                 text[m]=i;
22             }
23         }
24         printf("Scenario #%d\n",++T);
25         queue<int> Q;
26         queue<int> q[maxn];
27
28         while(true){
29             char a[10];
30             scanf("%s",a);
31             if(a[0]==‘S‘) break;
32             else{
33                 int n;
34                 if(a[0]==‘E‘){
35                     cin>>n;
36                     if(q[text[n]].size()==0) Q.push(n);
37                     q[text[n]].push(n);
38
39                 }
40                 else{
41                     n=Q.front();
42                     cout<<q[text[n]].front()<<endl;
43                     q[text[n]].pop();
44                     if(q[text[n]].empty()) Q.pop();       //The key point!
45                 }
46             }
47         }
48         cout<<endl;
49     }
50     return 0;
51 }
时间: 2024-10-16 22:58:58

Team Queue UVA - 540的相关文章

例题5-6 团体队列 Team Queue UVA - 540

还好吧,刚开始没想明白用什么数据结构来做,后来才想到用一个队列和一个队列数组,一个存当前队伍的排队队列,另一个存每个在排队的队伍内部的人员队列.其他的set什么的,都不是最重要的内容了. 卡了我三个点: 1.忘了控制空队出队,空队排头了,导致了RE一次.在写了判定条件之后RE没了,成了WA-_- 2.这次WA是因为没有及时清除中间变量.是比较隐含的中间变量,表示某个队伍是否已在总队伍中的set,我在某只队伍最后一个成员从总队伍中出队后,没有清楚set中这支队伍的标记.也就是说,这支队伍其实不存在

UVa 540 Team Queue(团队队列)

题意  模拟团队队列的入队和出队 STL应用  用一个队列维护团队编号  再用一个队列数组维护个体 #include <cstdio> #include <cstring> #include <queue> #include <map> using namespace std; const int N = 1000005; int team[N]; int main() { int cas = 0, n, t, a; char cmd[20]; while(

UVA - 540 Team Queue(STL,队列 )

Team Queue Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known,

【UVa 540】Team Queue

  Team Queue  Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front of the Mensa is a team

540 - Team Queue

Team Queue PS:因为该题排版较麻烦,这里给出OJ网址:UVa540 - Team Queue 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队友在排队,那么这个新人会插队到最后一个队友的身后.如果没有任何一个队友排队,则他会排到长队的队尾.输入每个团队中所有队员的编号,要求支持如下3种指令(前两种指令可以穿插进行). ENQUEUEx:编号为x的人进入长队. DEQUEUE:长队的队首出队. STOP:停止模拟. 对于每个DEQUEUE指令,输出出队的人的编号. #incl

UVA 540(队列)

Description  Team Queue  Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the queue in front of the Mensa

Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 129 Accepted Submission(s): 63   Problem Description Queues and Priority Queues are data structures which are known to most computer scie

Winter-2-STL-G Team Queue 解题报告及测试数据

Time Limit:3000MS     Memory Limit:0KB Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the q

HDU 1387 Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1889    Accepted Submission(s): 639 Problem Description Queues and Priority Queues are data structures which are known to most computer