HDU1387 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.
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.
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
101
102
103
201
202
203
Scenario #2
259001
259002
259003
259004
259005
260001
#include < queue >
#include < string >
#include < map >
#pragma warning (disable:4786)
using namespace std;
int main()
{
int i,n,m,t,ca = 1 ;
bool visit[ 1002 ];
char str[ 20 ];
while (scanf( " %d " , & n),n)
{
queue < int > q[ 1002 ],que;
map < int , int > team;
for (i = 0 ;i < n;i ++ )
{
scanf( " %d " , & m);
while (m -- )
{
scanf( " %d " , & t);
team[t] = i;
}
}
memset(visit, 0 , sizeof (visit));
printf( " Scenario #%d\n " ,ca ++ );
while (scanf( " %s " ,str))
{
if (strcmp(str, " STOP " ) == 0 )
{
puts( "" );
break ;
}
else if (strcmp(str, " ENQUEUE " ) == 0 )
{
scanf( " %d " , & t);
q[team[t]].push(t);
if (visit[team[t]] == false )
{
que.push(team[t]);
visit[team[t]] = true ;
}
}
else
{
printf( " %d\n " ,q[que.front()].front());
q[que.front()].pop();
if (q[que.front()].empty())
{
visit[que.front()] = false ;
que.pop();
}
}
}
}
return 0 ;
}
然后下一步该主攻《数论》了,要加油打个漂亮仗啊!!
转载于:https://www.cnblogs.com/DreamUp/archive/2010/07/22/1783004.html
HDU1387 Team Queue相关推荐
- 【队列】Team Queue(luogu-UVA540/poj 2259)
Team Queue luogu-UVA540 poj 2259 题目大意: 有n个小组的人要排队,每个小组中有若干个人,当一个人入队时,如果队中有自己小组的人就跟在此人后面,否则站在队尾,现在给出一 ...
- 540 - Team Queue
Team Queue PS:因为该题排版较麻烦,这里给出OJ网址:UVa540 - Team Queue 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队友在排队,那么这个新人会插队到最后一 ...
- UVa540 Team Queue
// 题意:有t个团队的人在排队.每次来了一个新人之后,如果他有队友在排队,那么这个新人会插队到队友的身后. // 要求支持三种指令:ENQUEUE x; DEQUEUE(队首出队); STOP.模拟 ...
- 解题报告——例题 5-6团体队列(Team Queue UVa 540)——31行代码解决
题目大意: 有t个团队的人正在排一个长队,每次新来一个人时,如果他有队友在排队,那么这个新人会插队到最后一个队友的身后.如果没有任何一个队友排队,那么他会排到长队的队尾.输入每个团队中所有队员的编号, ...
- UVA - 540:Team Queue
主要的关键在于:不要试图让所有团队的人在一个队列里面,因为这样如果新入队的是一个前面团队的成员则必须先出队再入队. 应该把每个团队看做一个整体,用一个队列维护团队的顺序,用t个队列维护每个团队内部的顺 ...
- POJ 2259 team queue团队排队问题
题目链接: http://poj.org/problem?id=2259 题目大意: 告诉你一堆人(m个人是一组的,n个人是一组的....):然后一个人来排队了,先看下有自己组的熟人吗?有的话直接排在 ...
- 【例题5-6 UVA 540 】Team Queue
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用两个队列模拟就好. 记录某个队在不在队列里面. 模拟 [错的次数] 在这里输入错的次数 [反思] 在这里输入反思 [代码] #in ...
- Poj2259 Team Queue 【队列】
http://poj.org/problem?id=2259 队列是一种先进先出的数据结构.它只允许在表的前端(front)进行删除操作,而在表的后端(rear)进行插入操作.进行插入操作的端称作队尾 ...
- UVA 540 Team Queue
题目链接:https://vjudge.net/problem/UVA-540 题目翻译摘自<算法禁赛入门经典> 题目大意 有 t 个团队的人正在排一个长队.每次新来一个人时,如果他有队友 ...
最新文章
- ap忘记管理ip地址怎么办_什么是无线AP?胖瘦AP如何区分?
- java登录界面命令_Java命令行界面(第18部分):JCLAP
- 中科慧眼双目安装pcl
- Python的内置函数的学习笔记
- 火狐浏览器插件大全,火狐插件大全,firefox插件使用方法
- 【HDOJ6957】Maximal submatrix(单调栈,最大子矩阵面积)
- 從零開始學 ReactJS:最完整的 React 生態系入門教程
- 02-微信小程序商城 顶部广告图片(微信小程序商城开发、小程序毕业设计、小程序源代码)(黄菊华-微信小程序开发教程)
- Python 实现Tracert追踪TTL值
- CMT2300A 433MHz SUB-1G无线收发芯片
- 软考新思维--2017年上半年信息系统项目管理师上午试题分析与答案(试题1-5题)
- 合肥耀之阳电商:店铺商品属性怎么样修改
- 获取图片上任意一点的颜色值
- 安装redis时被意外攻击 newinit
- Android自定义折线图,可设置基准线,不同点颜色
- PostgreSQL 14和SCRAM认证的改变--应该迁移到SCRAM?
- 响应式网站建设有什么优势?
- 洛谷 P3978 [TJOI2015]概率论
- 树莓派ADC(ADS1115)读取Voltage Sensor(电压检测模块)
- 知识见解关于高斯定理