{"trustable":false,"sections":[{"title":"","value":{"format":"PLAIN","content":"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.\nIn 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.\n\nInput\n\nThe input file will contain one or more test cases. Each test case begins with the number of teamst(1\u003c\u003dt\u003c\u003d1000). 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:\n•ENQUEUEx— enter elementxinto the team queue\n•DEQUEUE— process the first element and remove it from the queue\n•STOP— end of test case\nThe input will be terminated by a value of 0 fort.\nWarning: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.\nOutput\nFor 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.\nSample Input\n2\n3 101 102 103\n3 201 202 203\nENQUEUE 101\nENQUEUE 201\nENQUEUE 102\nENQUEUE 202\nENQUEUE 103\nENQUEUE 203\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nSTOP\n2\n5 259001 259002 259003 259004 259005\n6 260001 260002 260003 260004 260005 260006\nENQUEUE 259001\nENQUEUE 260001\nENQUEUE 259002\nENQUEUE 259003\nENQUEUE 259004\nENQUEUE 259005\nDEQUEUE\nDEQUEUE\nENQUEUE 260002\nENQUEUE 260003\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nSTOP\n0\nSample Output\nScenario #1\n101\n102\n103\n201\n202\n203\nScenario #2\n259001\n259002\n259003\n259004\n259005\n260001\n\n"}},{"title":"","value":{"format":"PLAIN","content":"队列和优先队列是大多数计算机科学家都知道的数据结构。然而,团队队列却不那么为人所知,尽管它在日常生活中经常出现。比如在午餐时间,门萨前的队伍就是一个团队队列。\n在团队队列中,每个元素都属于一个团队。如果一个元素进入队列,它首先从头到尾搜索队列,检查是否有队友(同队元素)已经在队列中。如果是,它就进入队列,紧随其后。如果没有,它就从队尾进入队列,成为新的最后一个元素(运气不好)。排队就像在普通的队列中一样:元素按照它们在队列中出现的顺序从头到尾进行处理.你的任务是写一个程序来模拟这样的队列。\n\n输入内容\n\n输入文件将包含一个或多个测试用例。每个测试用例都以teamst的数量(1\u003c\u003dt\u003c\u003d1000)开始。然后是t个团队描述,每个团队描述由属于该团队的元素数量和元素本身组成。元素是范围为0...99999的整数。一个团队最多可以由1000个元素组成。最后是一个命令列表。有三种不同的命令。\n-ENQUEUEx- 将元素输入到团队队列中去\n-DEQUEUE-处理第一个元素,并将其从队列中删除。\n-STOP-测试案例结束\n输入将以0 fort值结束。\nWarning:一个测试用例可能包含多达200000(二十万)条命令,所以团队队列的实现应该是高效的:一个元素的enqueing和dequeuing都应该只需要恒定的时间。\n輸出\n对于每个测试用例,首先打印一行 \"Scenario #k\",其中k是测试用例的编号。然后,对于每一条\u0027DEQUEUE\u0027命令,在一行上打印被dequeued的元素。在每个测试用例后,即使是最后一个测试用例,也要打印一行空白。\n输入示例\n2\n3 101 102 103\n3 201 202 203\nENQUEUE 101\nENQUEUE 201\nENQUEUE 102\nENQUEUE 202\nENQUEUE 103\nENQUEUE 203\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\n停止\n2\n5 259001 259002 259003 259004 259005\n6 260001 260002 260003 260004 260005 260006\nENQUEUE 259001\nENQUEUE 260001\nENQUEUE 259002\nENQUEUE 259003\nENQUEUE 259004\nENQUEUE 259005\nDEQUEUE\nDEQUEUE\nENQUEUE 260002\nENQUEUE 260003\nDEQUEUE\nDEQUEUE\nDEQUEUE\nDEQUEUE\n停止\n0\n采样输出\n情景1\n101\n102\n103\n201\n202\n203\n第2种情况\n259001\n259002\n259003\n259004\n259005\n260001\n\n"}}]}