F - Team Queue
有n个队伍。 对于每个ENQUEUE x 命令。 如果x所在的队伍已经在队列中, 则x排在队列中它的队伍的尾巴, 否则排在队列的末尾。 可以理解为队列中的队列的味道。
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 queue, for example.
In a team queue each element belongs to a team. If an element enters the queue, it first searches
the queue from head to tail to check if some of its teammates (elements of the same team) are already
in the queue. If yes, it enters the queue right behind them. If not, it enters the queue at the tail
and becomes the new last element (bad luck). Dequeuing is done like in normal queues: elements are
processed from head to tail in the order they appear in the team queue.
Your task is to write a program that simulates such a team queue.
Input
The input file will contain one or more test cases. Each test case begins with the number of teams
t (1 ≤ t ≤ 1000). Then t team descriptions follow, each one consisting of the number of elements
belonging to the team and the elements themselves. Elements are integers in the range 0..999999. A
team may consist of up to 1000 elements.
Finally, a list of commands follows. There are three different kinds of commands:
• ENQUEUE x — enter element x into the team queue
• DEQUEUE — process the first element and remove it from the queue
• STOP — end of test case
The input will be terminated by a value of 0 for t.
Warning: A test case may contain up to 200000 (two hundred thousand) commands, so the implementation
of the team queue should be efficient: both enqueing and dequeuing of an element should
only take constant time.
Output
For each test case, first print a line saying ‘Scenario #k’, where k is the number of the test case. Then,
for each ‘DEQUEUE’ command, print the element which is dequeued on a single line. Print a blank line
after each test case, even after the last one.
Sample Input
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
Sample Output
Scenario #1
101
102
103
201
202
203
Scenario #2
259001
259002
259003
259004
259005
260001
1 /*I*/
2 #include <bits/stdc++.h>
3 using namespace std;
4 map<int,int>mark;//二维数组x i
5 int main()
6 {
7 int t;
8 int cas=0;
9 while(cin>>t&&t)
10 {
11 printf("Scenario #%d\n",++cas);
12 mark.clear();
13 queue<int> q[1020];
14 queue<int> p;
15 for(int i=0;i<t;i++)
16 {
17 int n;
18 cin>>n;
19 while(n--)
20 {
21 int x;
22 cin>>x;
23 mark[x]=i; //记录编号为t的队员在第几小队i
24 }
25 }
26 string s;
27 while(cin>>s)
28 {
29 if(s[0]=='S') break;
30 if(s[0]=='E')
31 {
32 int n;
33 cin>>n;
34 int i=mark[n];
35 if(q[i].empty()) //如果这个队员没有在主队列中发现自己的队友
36 {
37 q[i].push(n);
38 p.push(i);
39 }
40 else
41 q[i].push(n);//发现了,插队orz
42 }
43 else if(s[0]=='D')
44 {
45 int i=p.front();
46 cout<<q[i].front()<<endl;
47 q[i].pop();
48 if(q[i].empty())
49 p.pop();
50 }
51 }
52 cout<<endl;
53 }
54 }
F - Team Queue的更多相关文章
- hdu 1387(Team Queue) STL
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue (uva540 队列模拟)
Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...
- ACM题目————Team Queue
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- HDU 1387 Team Queue
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue
Team Queue Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2471 Accepted: 926 Descrip ...
- Team Queue(多队列技巧处理)
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue(STL练习题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...
- Team Queue (HDU:1387)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- Team Queue POJ - 2259 (队列)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
随机推荐
- LeetCode498 对角线遍历
给定一个含有 M x N 个元素的矩阵(M 行,N 列),请以对角线遍历的顺序返回这个矩阵中的所有元素,对角线遍历如下图所示. 示例: 输入: [ [ 1, 2, 3 ], [ 4, 5, 6 ], ...
- spring中的工厂模式
spring的bean的创建原理就是框架利用反射创建出实例对象 工厂模式:工厂帮我们创建对象:有一个专门帮我们创建对象的类,我们把这个类叫做工厂类. 例如:Plane plane = PlaneFac ...
- maven依赖与传递性依赖
目录 依赖范围 传递性依赖 依赖调节 可选依赖 本文主要是针对<maven实战>书中关键知识点的学习记录,未免有纰漏或描述不到之处,建议购买阅读原书 首先贴出一个pom常见的一些元素释义 ...
- (十二)random模块
大致有以下几个函数: print(random.random()) #0到1的浮点型 print(random.randint(1,6)) #1到6的整型 print(random.randrange ...
- mysqldump 的-T参数
/usr/local/mysql/bin/mysqldump -uroot -T /tmp lina xuehao 把lina数据库中的xuehao表在tmp目录下备份出来两个文件,一个是纯数据.tx ...
- 【Linux】saltstack的使用详解 超详细
一.salt常用命令 salt 该命令执行salt的执行模块,通常在master端运行,也是我们最常用到的命令 salt [options] '<target>' <function ...
- LOOP语句的AT语句块
在loop一个内表的时候,如果想在loop循环中使用AT NEW ,AT END OF 等语句,一定需要注意的几点: 1.内表要排序 2.AT END OF 语句中影响的是指定字段前面所有的字段 3. ...
- 微信小程序代码上传,审核发布小程序
1.打开微信开发者工具 管理员扫码 -> 填写好小程序的项目目录.AppID(必须是客户已注册好的AppID).项目名称 2.在app.js中修改id(客户登录后台管理系统的id),app.js ...
- Linux的环境变量配置在/etc/profile或/etc/profile.d/*.sh文件中的区别是什么?
@ 目录 login shell non-login shell 它们的区别 Linux的环境变量可在多个文件中配置,如/etc/profile,/etc/profile.d/*.sh,~/.bash ...
- NULL-safe equal null 索引 空字符串
小结 1. mysql> INSERT INTO my_table (phone) VALUES (NULL); 有手机号但是不知道 mysql> INSERT INTO my_table ...