HDU 1387 Team Queue
Team Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1889 Accepted Submission(s): 639
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 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.
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.
#include <bits/stdc++.h>
using namespace std; map<int, int> mp;
char op[10];
int t, n, p, cn = 0; int main()
{
while(scanf("%d", &t), t){
mp.clear();
printf("Scenario #%d\n", ++cn);
for(int i = 0; i < t; ++i){
scanf("%d", &n);
while(n--){
scanf("%d", &p);
mp[p] = i;
}
}
queue<int> q1[1005];
queue<int> q2;
while(scanf("%s", op), op[0] != 'S'){
if(op[0] == 'E'){
scanf("%d", &p);
int id = mp[p];
if(q1[id].empty())
q2.push(id);
q1[id].push(p);
}
else if(op[0] == 'D'){
int id = q2.front();
printf("%d\n", q1[id].front());
q1[id].pop();
if(q1[id].empty())
q2.pop();
}
}
printf("\n");
}
return 0;
}
HDU 1387 Team Queue的更多相关文章
- HDU 1387 Team Queue( 单向链表 )
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1387 Team Queue (链表)
题目大意: 不同的人在不同的队伍里,插入链表的时候假设这个链表里有他的队友,就把它放到最后一个队友的最后.假设没有队友,就把它放到整个链表的最后面. 出链表的时候把第一个人拿出来. 思路分析: 要模拟 ...
- Team Queue(STL练习题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...
- hdu 1387(Team Queue) STL
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue (HDU:1387)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- 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 ...
- 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 ...
随机推荐
- Unity3d修改FBX文件的动画名方法
问题描述:FBX文件导入Unity3d后的动画名字一般都是 “Take 001”并且无法修改!如何修改它呢? 解决方法:解决方法其实很简单,只要你按照Unity3d的FBX文件命名规则,压根就不会存在 ...
- Libsvm学习
本篇博客转自 http://www.cppblog.com/guijie/archive/2013/09/05/169034.html 在电脑文件夹E:\other\matlab 20 ...
- QC、IQC、IPQC、FQC、OQC、QA分别的定义
QC:即英文(Quality Control)的简称,中文意义是品质控制,其在ISO8402:1994的定义是“为达到品质要求所采取的作业技术的活动”.有些推行ISO9000的组织会设置这样一个部门或 ...
- java使用正则表达式验证IP V4、 IP V6
package cn.outofmemory.snippets.core; import java.util.regex.Pattern; /** * A collection of utilitie ...
- The Introduction of Java Memory Leaks
One of the most significant advantages of Java is its memory management. You simply create objects a ...
- 59. Spiral Matrix II
题目: Given an integer n, generate a square matrix filled with elements from 1 to n2 in spiral order. ...
- Java API —— 网络编程
1.网络编程概述 1)网络编程概述 · 计算机网络 是指将地理位置不同的具有独立功能的多台计算机及其外部设备,通过通信线路连接起来,在网络操作系统,网络管理软件及网络通 ...
- sqlplus时报Linux-x86_64 Error: 13: Permission denied
在本机上非oracle用户运行sqlplus时,报以下错误:[cpdds@node1 ~]$ sqlplus cpdds_pdata/cpdds_pdata SQL*Plus: Release 10. ...
- Unrecognized selector sent to instance xxxxxxx
两个界面传递参数时报这个错误,经检查发现,是因为目标视图没有关联对应的controller.
- linux内核下载
01最新版:https://www.kernel.org/ 02老旧版:https://www.kernel.org/pub/linux/kernel/v3.x/ ------------------ ...