题意:

每个人都属于一个团体,在排队的时候,如果他所在的团体有人在队伍中,则他会站到这个团体的最后。否则站到整个队伍的队尾。

输出每次出队的人的编号。

分析:

容易看出,长队中,在同一个团体的人是排在一起的。

所以用两个队列模拟即可,一个队列保留团体的编号,另外一个队列数组存放的是团体中每个人的编号。

 #include <cstdio>
#include <queue>
#include <map>
using namespace std; const int maxt = + ;
map<int, int> team;
char cmd[]; int main()
{
//freopen("in.txt", "r", stdin); int T, kase = ;
while(scanf("%d", &T) == && T)
{
printf("Scenario #%d\n", ++kase); for(int i = ; i < T; i++)
{
int n, x;
scanf("%d", &n);
while(n--) { scanf("%d", &x); team[x] = i; }
}
queue<int> q, q2[maxt]; //团体队列 和 q2[i]表示团体i中成员的队列 while(scanf("%s", cmd) == )
{
if(cmd[] == 'S') break;
if(cmd[] == 'E')
{
int x, t;
scanf("%d", &x);
t = team[x];
if(q2[t].empty()) q.push(t);
q2[t].push(x);
}
else if(cmd[] == 'D')
{
int t = q.front();
printf("%d\n", q2[t].front());
q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
puts("");
} return ;
}

代码君

UVa 540 (团体队列) Team Queue的更多相关文章

  1. uva 540 - Team Queue(插队队列)

    首发:https://mp.csdn.net/mdeditor/80294426 例题5-6 团体队列(Team Queue,UVa540) 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队 ...

  2. UVA.540 Team Queue (队列)

    UVA.540 Team Queue (队列) 题意分析 有t个团队正在排队,每次来一个新人的时候,他可以插入到他最后一个队友的身后,如果没有他的队友,那么他只能插入到队伍的最后.题目中包含以下操作: ...

  3. UVA 540 Team Queue(模拟+队列)

    题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...

  4. 【UVA - 540】Team Queue (map,队列)

    Team Queue Descriptions: Queues and Priority Queues are data structures which are known to most comp ...

  5. UVa 540 Team Queue 【STL】

    题意:给出t个团体,这t个团体排在一起,每次新来一个x排队,如果在整个的团体队列中,有x的队友,那么x排在它的队友的后面,如果他没有队友,则排在长队的队尾 求给出的每一个出队命令,输出出队的人的编号 ...

  6. uva 540 (Team Queue UVA - 540)

    又是一道比较复杂的模拟题.题中有两种队列,一种是总队列,从前向后.其他的是各个团体的小队列,因为入队的人如果有队友的话,会优先进入团体队列. 所以我们先设置两个队列和一个map,设置map倒是可以不用 ...

  7. Team Queue UVA - 540

      Queues and Priority Queues are data structures which are known to most computer scientists. The Te ...

  8. Team Queue (uva540 队列模拟)

    Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...

  9. Team Queue(多队列技巧处理)

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. delphi 自带报告内存泄漏

    //报告内存泄漏 ReportMemoryLeaksOnShutdown := true;

  2. Ubuntu安装google Gtest

    (1) 下载源码:http://code.google.com/p/googletest/gtest-1.7.0 (2013)gtest-1.7.0 (2010) (2) README编译指南126 ...

  3. Ajax的理解

    初学JS,一直认为Ajax是个很高级的.不可亵玩的东西.这两天怀着忐忑的心情接触了一下它, 感觉它并没有想象中的那么难理解. 其实,Ajax就是浏览器端向服务器请求资源的一个对象(方法). 就跟打电话 ...

  4. PHP核心代码库中的APC缓存说明123

    1.APC缓存简介APC,全称是Alternative PHP Cache,官方翻译叫”可选PHP缓存”.它为我们提供了缓存和优化PHP的中间代码的框架. APC的缓存分两部分:系统缓存和用户数据缓存 ...

  5. 关于分区技术的索引 index

    关于分区技术---索引 Index 一.   分区索引分类: 本地前缀分区索引(local prefixedpartitioned index) 全局分区索引(global partitionedin ...

  6. psutil--跨平台的进程管理

    原文地址:http://www.jianshu.com/p/64e265f663f6 Python处理Windows进程 psutil(Python system and process utilit ...

  7. redis参考

    www.redis.cn www.redis.io http://blog.nosqlfan.com/ 可以移步http://try.redis.io/进行实验命令 Redis 设计与实现(第一版) ...

  8. cocos2dx-Lua中出现的问题

    1,在Lua中print输出失效的问题 在main.lua中添加print=release_print :

  9. 纯CSS制作二级导航

    一.问题描述 做一个类似校园网首页,主要是导航栏的设置,ul默认纵向排列,如何横向排列,同时去掉圆点. 二.问题解决 2.1 先写导航条 用两个ul嵌套,一个ul是横向导航条,另一个是每个小项目下连一 ...

  10. jsp的静态包含与动态包含:<%@ include file="" %>和<jsp:include page=""></jsp:include>区别与分析

    <%@ include file="" %>是将文件原封不动的copy进现有的文件中,像是拼接好后,再编译成为servlet运行. <jsp:include pa ...