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

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

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. vim简单的配置

    "设置当文件被改动时自动载入 set autoread "在左侧行号 set nu "tab长度为4 "覆盖文件时不备份 set nobackup " ...

  2. jQuery table tr隔行变色,鼠标移入移出变色,鼠标点击变色

    .trover { background: #f9f9f9; } .trclick { background: #c4e8f5; } .treven{ background:#CCFFCC; } .t ...

  3. 2017-2018-2 20165330实验二《Java面向对象程序设计》实验报告

    实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验步骤 (一)单元测试 三种代码 伪代码:从意图层面来解 ...

  4. Win7环境下 IIS配置

    一.介绍IIS Internet Information Services(IIS,互联网信息服务),是由微软公司提供的基于运行Microsoft Windows的互联网基本服务.最初是Windows ...

  5. Ubuntu 下 mysql 卸载后重安装时遇到的问题

    卸载mysql报错解决方法1 dpkg: error processing mysql-server (--configure): dependency problems - leaving unco ...

  6. Mysql日常操作

    创建用户并授权 grant all privileges on test.* to "test"@"localhost" identified by " ...

  7. Linux下的物理内存管理2-slab缓存的管理

    2017-03-02 在Linux下的物理内存管理中,对SLAB机制大致做了介绍,对SLAB管理结构对象也做了介绍,但是对于小内存块的分配没有介绍,本节重点介绍下slab对小内存块的管理. 内核中使用 ...

  8. django模型:为已存在的表建立模型

    为已经存在的表建立模型:参考https://blog.csdn.net/opera95/article/details/78200024 为已经存在的表建立模型1.python manage.py i ...

  9. (0.2.5)Mysql安装——RPM方式安装

    rpm安装mysql 卸载与安装服务端   一.安装服务端与客户端 #查看RPM包中所有的文件shell> rpm -qpl mysql-community-server-version-dis ...

  10. vs2010 重新配置帮助文档

    1.VS2010帮助文件不支持重新配置,这个时候打开C:\Program Files\Microsoft Help Viewer\1.0目录,找到“HelpLibManager.exe.config” ...