第一遍看的时候立即想到了哈希表。

再想时觉得两个队列,一个用来排队伍之间的顺序,一个用来排队伍内部成员的顺序即足够了。

DEQUE的时候先判断哪只队伍排在队首,之后再让该队伍中的首队员出列。

整体没有什么难度,注意的一些小tips如下:

1、多个测试用例一定注意先初始化(因为这个wa了两次。。呃呃)

2、判断是否需要进行队伍排序可以另立一个flag数组用来标记某支队伍是否已经在队列中,若不在则插入该队伍序号。

3、别忘了按要求输出(最后空一行,否则就PE了)

ac代码如下:

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
const int maxn=;
queue<int> pno[maxn];//各个team内部排序
queue<int> tno;//team排序
int teamflg[maxn];
int main(void) {
int t;
map<int,int> pt;//队伍与人
int se=;
while(scanf("%d",&t)&&t){
//初始化 (一开始忘了这茬,wa了两次。。。)
memset(teamflg,,sizeof(teamflg));
while(tno.empty()==)tno.pop();
for(int i=;i<maxn;i++){
if(pno[i].empty()==){
while(pno[i].empty()==)pno[i].pop();
}
}
printf("Scenario #%d\n",++se);
for(int i=;i<t;i++){
int num;
cin>>num;
for(int j=;j<num;j++){
int person;
cin>>person;
pt[person]=i;
}
}
string op; while(true){
cin>>op;
if(op[]=='S')break;
else if(op[]=='E'){
int p;
cin>>p;
int team=pt[p];
pno[team].push(p);
if(teamflg[team]==){
tno.push(team);
teamflg[team]=;
}
}
else if(op[]=='D'){
int team=tno.front();
int out=pno[team].front();
pno[team].pop();
printf("%d\n",out);
if(pno[team].empty()==){
tno.pop();
teamflg[team]=;
}
}
}
cout<<endl;
}
return ;
}

poj-2259 team queue(数据结构)的更多相关文章

  1. poj 2259 Team Queue

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

  2. POJ 2259 Team Queue(队列)

    题目原网址:http://poj.org/problem?id=2259 题目中文翻译: Description 队列和优先级队列是大多数计算机科学家已知的数据结构. 然而,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. (队列的应用5.3.2)POJ 2259 Team Queue(队列数组的使用)

    /* * POJ_2259.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...

  5. queue POJ 2259 Team Queue

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

  6. Team Queue POJ - 2259 (队列)

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

  7. hdu 1387(Team Queue) STL

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

  8. Team Queue (uva540 队列模拟)

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

  9. ACM题目————Team Queue

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

  10. HDU 1387 Team Queue

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

随机推荐

  1. ZOJ 3715 Kindergarten Election

    At the beginning of the semester in kindergarten, the n little kids (indexed from 1 to n, for conven ...

  2. [genome shell]标题栏优化

    参考地址:https://wiki.archlinux.org/index.php/GNOME_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)#.E4.BB.8E.E5. ...

  3. rabbitMQ 安装,集群搭建, 编码

    RabbitMQ 一.背景 命令行工具: http://www.rabbitmq.com/man/rabbitmqctl.1.man.html 介绍入门文章: http://blog.csdn.net ...

  4. webpack无法通过 IP 地址访问 localhost 解决方案

    解决方案: 在config里面的index.js里面的module.exports下面的dev下面的host:'localhost' 改为 host:'0.0.0.0',就可以访问啦!

  5. (2.10)备份与还原--利用T-SQL进行备份还原

    常用: /************ 一.数据库备份 ************/ with init,format,stats=1init:覆盖format:格式化备份集stats=1:显示进度条 ST ...

  6. shell调用python脚本,并且向python脚本传递参数

    1.shell调用python脚本,并且向python脚本传递参数: shell中: python test.py $para1 $para2 python中: import sys def main ...

  7. Linux shell 程序设计

    shell 程序设计 主要的学习内容包含基本思路,语法:变量.条件判断和程序控制,命令列表,函数,命令及执行,调试,grep命令和正则表达式,find命令 什么是shell 适用编写执行相对简单任务的 ...

  8. lnmp1.4环境下thinkphp3.2配置pathinfo模式

    1.打开php.ini 通常该文件在 /usr/local/php/etc/php.ini vi /usr/local/php/etc/php.ini 找到 cgi.fix_pathinfo,默认为0 ...

  9. 专项训练知识点与错题整理-nowcoder-c++

    1- 来自:http://www.cskaoyan.com/thread-595813-1-1.html 1.拷贝构造函数 转自:https://www.cnblogs.com/alantu2018/ ...

  10. .htaccees什么鬼?怎么用?

    .htaccess文件全称Hypertext Access(超文本入口).提供了针对目录改变配置的方法, 即,在一个特定的文档目录中放置一个包含一个或多个指令的文件, 以作用于此目录及其所有子目录.作 ...