题意:有若干个团体,每个团体有若干个元素,他们按次序来排队,如果队列中已经有同一团体的元素在,则可以插队到它后面,模拟这个过程

思路:用map存下元素与团体的关系,并开2个队列,一个存整体队伍的排列(毕竟同一个团体的元素会连在一起),另一个存每个团体内部的排列。

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int read(){
char ch=getchar();int f=,t=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
int n,T=;
while (scanf("%d",&n)!=EOF&&n!=){
printf("Scenario #%d\n",++T);
map<int,int>mp;
for (int i=;i<=n;i++){
int x=read();
while (x--){
mp[read()]=i;
}
}
queue<int> qAll,qTeam[];
char s[];
scanf("%s",s);
while (s[]!='S'){
if (s[]=='E'){
int x=read();
int y=mp[x];
if (qTeam[y].empty()) qAll.push(y);
qTeam[y].push(x);
}else if (s[]=='D'){
int x=qAll.front();
printf("%d\n",qTeam[x].front());qTeam[x].pop();
if (qTeam[x].empty()) qAll.pop();
}
scanf("%s",s);
}
printf("\n");
}
}

Team Queue(POJ 2259)的更多相关文章

  1. Team Queue POJ - 2259 (队列)

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

  2. queue POJ 2259 Team Queue

    题目传送门 题意:先给出一些小组成员,然后开始排队.若前面的人中有相同小组的人的话,直接插队排在同小组的最后一个,否则只能排在最后面.现在有排队和出队的操作. 分析:这题关键是将队列按照组数分组,用另 ...

  3. POJ 2259 - Team Queue - [队列的邻接表]

    题目链接:http://poj.org/problem?id=2259 Queues and Priority Queues are data structures which are known t ...

  4. poj 2259 Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Descri ...

  5. POJ 2259 Team Queue(队列)

    题目原网址:http://poj.org/problem?id=2259 题目中文翻译: Description 队列和优先级队列是大多数计算机科学家已知的数据结构. 然而,Team Queue并不是 ...

  6. hdu 1387(Team Queue) STL

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

  7. Team Queue (uva540 队列模拟)

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

  8. ACM题目————Team Queue

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

  9. HDU 1387 Team Queue

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

随机推荐

  1. mysql 设置字符集

    可以用:show create table table_name查看建表信息 也可用: show create database database_name查看建库信息 mysql> creat ...

  2. mssql手工注入2

    --+ 先说一些函数的说明: substring(str,start,len) 截取字符串的作用,第一个参数为要截取的字符串,第二个参数为从哪里开始截取,第三个参数为截取的长度 ascii(char) ...

  3. sublime3插件安装及报错处理

    ctrl+shift+p调用出窗口:输入install package,然后输入想安装的插件. 有些用户安装的可能是国内破解版的,我的就是,然后install package报错: Package C ...

  4. C#反射动态调用dll中的方法及使用QuartZ.net实现作业调度

    using Quartz; using Quartz.Impl; using System; using System.Collections.Generic; using System.Linq; ...

  5. xshell+xming连接服务器虚拟机启动mininet网络

    困于vnc连实验室的服务器虚拟机,一直出现页面不稳定的情况,然后本机虚拟机又带不起来,今天跟学弟交流,知道了ssh连接服务器的办法,心情好晴朗! xshell下载和安装,xshell使用 xshell ...

  6. Java Redis 连接池 Jedis 工具类

    import org.slf4j.Logger; import org.slf4j.LoggerFactory; import redis.clients.jedis.Jedis; import re ...

  7. shell中引号的作用(转)

    引号的作用 1 双引号(“”) 1)使用””可引用除字符$(美元符号).`(反引号).\(反斜线)外的任意字符或字符串.双引号不会阻止shell对这三个字符做特殊处理(标示变量名.命令替换.反斜线转义 ...

  8. mac pro 安装mysql并且配置my.cnf(添加默认字符集utf8,数据存放路径,修改已经建好的表的默认字符集等)、mac mysql my.cnf路径

    如果你是还没有下载安装文件,请到官网下载http://dev.mysql.com/downloads/mysql/ 下载好mysql的mac版本的安装文件后解压后将文件放到目录 /usr/local/ ...

  9. P1474 货币系统 Money Systems(完全背包求填充方案数)

    题目链接:https://www.luogu.org/problemnew/show/1474 题目大意:有V种货币,求用V种货币凑出面值N有多少种方案. 解题思路:就是完全背包问题,只是将求最大价值 ...

  10. textarea在浏览器中固定大小

    HTML 标签 textarea 在大部分浏览器中只要指定行(rows)和列(cols)属性,就可以规定 textarea 的尺寸,大小就不会改变,不过更好的办法是使用 CSS 的 height 和 ...