题意:

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

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

分析:

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

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

 #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. 国产CPU研究单位及现状

    1.国产CPU主要研制单位 (1)高性能通用CPU(“大CPU”,主要应用于高性能计算及服务器等) 主要研发单位:中国科学院计算所.北大众志.国防科技大学.上海高性能集成电路设计中心 (2)安全适用计 ...

  2. SelectedValue,SelectedValuePath,SelectedValueBinding,DisplayMemberPath讲解

    无论在Winform.WPF.ASP.NET中,数据绑定是我们经常使用的一个重要技术,我们经常会把相关类动态显示绑定到UI界面中,其中有几个比较重要的属性需要大家灵活运用. 那Combox来说明有两个 ...

  3. 字符串做异或使用union

    #include <stdio.h> #include <sys/time.h> #include <string.h> union data { unsigned ...

  4. oracle中的dual表详解

    oracle中的dual表详解 1.DUAL表的用途 Dual 是 Oracle中的一个实际存在的表,任何用户均可读取,常用在没有目标表的Select语句块中 --查看当前连接用户 SQL> s ...

  5. GNU_makefile_template

    #g++ compiler: options # -std=c++0x enables ISO C++ 11 standard # -I.. pulls in the Version_test.h f ...

  6. iOS 的UINavigationController详解与使用添加UIBarButtonItem

    转发自:http://blog.csdn.net/totogo2010/article/details/7681879 分类: iOS开发入门2012-06-21 11:10 53077人阅读 评论( ...

  7. 懒惰的JY--关于遍历

    先上题: [问题描述] 众所周知,JY的百度搜索算法已经练的炉火纯青,任何搜索题都能0.000ms出解. 不幸的是,JY遇到了一道百度搜索算法解决不了的题目,题目是这样的: 给定N个数A[1] A[2 ...

  8. JQuery 知识点

    1:animate 动画效果 $(function () { $(".sidebar-nav a").mouseover(function () { $(this).animate ...

  9. 同一台Windows机器中启动多个Memcached服务

    同一台Windows机器中启动多个Memcached服务 这就需要在一台机器上启动多个Memcached服务了. 假设Memcached在如下目录:C:\memcached\memcached.exe ...

  10. Mysql异常:MySQLNonTransientConnectionException: No operations allowed after statement closed

    Mysql异常:MySQLNonTransientConnectionException: No operations allowed after statement closed MySQLNonT ...