HDU 1387 Team Queue (队列模拟)
来源:互联网 发布:淘宝捉猫猫四星怎么抓 编辑:程序博客网 时间:2024/06/05 17:38
Team Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 140 Accepted Submission(s): 66Problem 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 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.
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 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.
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.
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
23 101 102 1033 201 202 203ENQUEUE 101ENQUEUE 201ENQUEUE 102ENQUEUE 202ENQUEUE 103ENQUEUE 203DEQUEUEDEQUEUEDEQUEUEDEQUEUEDEQUEUEDEQUEUESTOP25 259001 259002 259003 259004 2590056 260001 260002 260003 260004 260005 260006ENQUEUE 259001ENQUEUE 260001ENQUEUE 259002ENQUEUE 259003ENQUEUE 259004ENQUEUE 259005DEQUEUEDEQUEUEENQUEUE 260002ENQUEUE 260003DEQUEUEDEQUEUEDEQUEUEDEQUEUESTOP0
Sample Output
Scenario #1101102103201202203Scenario #2259001259002259003259004259005260001
Source
University of Ulm Local Contest 1998
题意给出队伍的信息跟队伍中个体的编号,然后先按照队伍的先后、再按照队伍中个体的先后进行输出。 有种插队的感觉(
#include <stdio.h>#include <iostream>#include <algorithm>#include <cmath>#include <string>#include <vector>#include <string.h>#include <memory>#include <queue>#include <stack>#include <map>using namespace std;int main () { map<int, int> mp; char str[20]; int t, n, p; int cn = 1; while (cin >> t && t) { mp.clear(); cout << "Scenario #" << cn++ << endl; for (int i = 0; i < t; ++i) { cin >> n; while (n--) { cin >> p; mp[p] = i; } } queue<int> que[1005]; queue<int> ans; while (cin >> str && str[0] != 'S') { if (str[0] == 'E') { cin >> p; int id = mp[p]; if (que[id].empty()) { ans.push(id); } que[id].push(p); } else if (str[0] == 'D') { int id = ans.front(); cout << que[id].front() << endl; que[id].pop(); if (que[id].empty()) ans.pop(); } } cout << endl; }}
阅读全文
0 0
- HDU 1387 Team Queue 队列的模拟
- HDU 1387 Team Queue (队列模拟)
- hdu 1387 Team Queue 优先队列
- Hdu 1387 Team Queue[队列 || 链表]
- hdu 1387 Team Queue(队列的嵌套)
- HDU 1387 Team Queue(优先队列)
- HDU - problem 1387 Team Queue【队列】
- HDU 1387 Team Queue (嵌套队列)
- Team Queue (uva540 队列模拟)
- HDU-1387-Team Queue
- hdu 1387 Team Queue
- HDU 1387 Team Queue
- HDU 1387 Team Queue
- hdu 1387 Team Queue
- uva 540 Team Queue(队列+模拟)
- uva540 Team Queue(模拟:队列)
- uva 540 Team Queue (队列模拟)
- uvaoj 540 Team Queue 队列模拟
- 基础DP01(POJ1163, HDU1421,POJ2533)
- mysql日常记录
- C++ String16转换成 const char*
- 【转】Unity 协程
- MQ消息中间件技术
- HDU 1387 Team Queue (队列模拟)
- elasticsearch了解垃圾收集器
- SQL Server 使用触发器(trigger)发送电子邮件步骤详解
- linux bash command not found
- Fragment设计的工厂模式
- 集合框架
- 纯CSS实现从中间延展的下划线
- 向MySQL中插入表情符号
- 基于OpenCV的离散哈特莱变换