Zzuli_team_practice (1) POJ 2259...__ Summer Camp Training

Source: Internet
Author: User
Tags time limit
Team Queue P time limit:2000ms Memory limit:65536kb 64bit IO Format:%i64d &%i64u
[Submit]   [Go back] [Status]
Description
Queues and Priority queues are data structures which are known to most computer. The team Queue, however, isn't so-so-known, though it occurs often in everyday life. At lunch time the queue in front of the Mensa are a team queue, for example.
In a team queue, each element, belongs to a. If an element enters the queue, it's the searches the queue from head to tail to check if some of it 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 doing like in normal queues:elements are processed from head to tail in the order they appear in the team que Ue.
Your task is to write a, simulates such a team queue. Input
The input would contain one or more test cases. Each test case is 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 them Selves. Elements are integers in the range 0-999999.  A team may consist of the 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 "the" and remove it from the queue
Stop-end of test case
The input would 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 Sho Uld be Efficient:both enqueing and dequeuing of a element should only take the time. Output
For each test case, the "scenario #k" in the "saying", where K is the number of the ' test case. Then, for each dequeue command, print the element which was dequeued on a single line. Print a blank line after each test case, even after the last one.
Sample Input
2 3 102 3 201 203 ENQUEUE The ENQUEUE 201 ENQUEUE 102 ENQUEUE ENQUEUE ENQUEUE 203 dequeue dequeue EUE DEQUEUE DEQUEUE DEQUEUE STOP 2 5 259001 259002 259003 259004 259005 6 260001 260002 260003 260004 260005 260006 ENQUEU E 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 ... At first the captain said the wrong word, the result WA several times, oneself look after know completely is not so, the idea is to join the queue to see whether it contains and he a team, some words added in the last team behind, no words added to the end of the entire queue code: C Language: Temporary use code # Include<stdio.h>
#include <string.h>
int que [200008], end;
int map [1000000];
void Insert (int a, int top)
{
int I, k;
K =-1;
for (i = top-1 i >= end; I-)
{
if (map [a] = = map [que [i]])
{
K = i;
break;
}
if (k ==-1) que [top] = A;
else {
for (i = top-1 i > k; i-)
que [i + 1] = que [i];
que [i + 1] = A;
}
}
int main ()
{
int N, M, A, flag = 0, top;
Char str [15];
while (scanf ("%d", &n), N)
{
memset (map, 0, sizeof (map));
Flag + +;
while (n--)
{
scanf ("%d", & M);
while (M--)
{
scanf ("%d", & A);
Map [a] =n;
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.