UVa 540 Team Queue:STL list&queue模拟插队

540 - Team Queue

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_problem&problem=481

Queues and Priority Queues are data structures which are known to most computer scientists. TheTeam 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 itsteammates (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 teamst (

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", wherek is the number of the test case. Then, for eachDEQUEUE 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

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索test
, case
, queue
, element
, The
, Team
dequeue()
uva540、uva lou s list、teamviewer、teambition、teamviewer12,以便于您获取更多的相关知识。

时间: 2024-10-02 08:55:32

UVa 540 Team Queue:STL list&queue模拟插队的相关文章

uva 540 Team Queue

点击打开链接uva 540 思路: list+map模拟 分析: 1 题目的意思是有n个队伍,每个队伍的人数为m. 2 现在有三种操作,ENQUEUE x是插入x,如果队列里面已经有x这一队的成员那么直接插入到这一队的最后一个,否则插入到队列的最后一个:DEQUEUE 是直接拿到队列的第一个元素输出,并删除队列的第一个元素:STOP是停止 3 直接利用map和list来模拟,由于题目要求要插入的具体的位置所以用list来模拟 代码: #include<map> #include<list

UVa 540:Team Queue 数据结构专题

题目链接: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=103&page=show_problem&problem=481 题目类型: 数据结构, 二叉树 样例输入: 2 3 101 102 103 3 201 202 203 ENQUEUE 101 ENQUEUE 201 ENQUEUE 102 ENQUEUE 202 ENQUEUE 103 ENQUEUE 2

STL之stack,queue,优先队列

 1.stack,size(),empty(),pop()函数 #include<stack> #include <iostream>   using namespace std;   //通过push()方法入栈 //通过size()方法求栈中元素的个数 //通过empty()方法判断栈是否为空 //通过pop()求栈中最顶端的元素 void main() {     int num;     cin >> num;     stack<int> my

UVa 496 Simply Subsets (STL&amp;amp;set_intersection)

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=437 先介绍<algorithm>头文件中与集合运算有关的4个函数: 查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/ 很明显,这里要判断两个集合的关

C++ STL容器stack和queue详解_C 语言

stack是一个比较简单的容器,它的使用也很简单,stack是LIFO容器,就是后进先出,最后添加进去的元素,第一个取出来 stack初始化 std::stack<int> first; std::stack<int> second(first); std::stack<int, std;:vector<int>> third; //使用vector初始化stack ### stack常用方法### empty();//判断是否为空 push(Elem e)

UVa 120 Stacks of Flapjacks (STL deque&amp;amp;reverse)

120 - Stacks of Flapjacks Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=56 Background Stacks and Queues are often considered the bread and butter of dat

C#中Queue的线程安全问题

通过集合枚举在本质上不是一个线程安全的过程.甚至在对集合进行同步处理时,其他线程仍可以修改该集合,这会导致枚举数引发异常.若要在枚举过程中保证线程安全,可以在整个枚举过程中锁定集合,或者捕捉由于其他线程进行的更改而引发的异常. 下列示例说明如何同步 Queue.如何确定 Queue 是否同步以及如何使用同步的 Queue.Unity3D教程手册 using System; using System.Collections; public class SamplesQueue { public s

【Python】模块之queue

  Queue类即是一个队列的同步实现.队列长度可为无限或者有限.可通过Queue的构造函数的可选参数maxsize来设定队列长度.如果maxsize小于1就表示队列长度无限. 创建一个 队列 对象 最大长度为10 from Queue import Queue q = Queue(maxsize = 10)   import Queue q = Queue.Queue(maxsize = 10)   python queue模块有三种队列: 1.python queue模块的FIFO队列先进先

ORA-23616: Failure in executing block 3 for script 删除queue的方法

ERROR at line 1: ORA-23616: Failure in executing block 3 for script E45713597D0EFA08E04010AC280A05F2 ORA-06512: at "SYS.DBMS_RECOVERABLE_SCRIPT", line 593 ORA-06512: at "SYS.DBMS_RECOVERABLE_SCRIPT", line 616 ORA-06512: at "SYS.DB