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

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

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. Microsoft Excel 标题栏或首行锁定

    Microsoft Excel 标题栏或首行锁定 在进行Excel编辑的时候,希望在浏览的时候,第一行或者第一列能够始终显示. 需要做的是:在Excel中选择 "视图"->& ...

  2. 剑指Offer——字符流中第一个不重复的字符

    题目描述: 请实现一个函数用来找出字符流中第一个只出现一次的字符.例如,当从字符流中只读出前两个字符"go"时,第一个只出现一次的字符是"g".当从该字符流中读 ...

  3. VC++SDK编程——字体及位置示例

    #include <Windows.h> #include <tchar.h> #include <math.h> #define PI 3.1415926 BOO ...

  4. matrix---简单dp,边界边界-_-

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5569 简单dp,恶心的边界处理,无语: if((i+j)%2==1) dp[i][j]=a[i-1][ ...

  5. 7.Git工作区和暂存区

    Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 1.工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的test文件夹就是一个工作区 ...

  6. Php 创建XML

    Php 创建XML  Php 创建XML并保存,学习示比例如以下: <? php try{ //创建DOMDocument 对象 $dom = new DOMDocument("1.0 ...

  7. java 多线程 day14 Semaphore 线程信号灯

    import java.util.concurrent.ExecutorService;import java.util.concurrent.Executors;import java.util.c ...

  8. python学习笔记(十九)发送邮件

    在python开发项目或者做自动化测试时候,在测试完成后需要将测试结果总结后进行上报,那么我们就可以通过发送邮件来完成这项工作. 下面我们来看看python中怎么发送邮件的,python中发送邮件可以 ...

  9. extern,头文件和ifndif宏

    转自:CSDN->fpmystar 用#include可以包含其他头文件中变量.函数的声明,为什么还要extern关键字,如果我想引用一个全局变量或函数f(),我只要直接在源文件中包含#incl ...

  10. Restful概念

    文章节选自: http://www.ruanyifeng.com/blog/2011/09/restful https://www.zhihu.com/question/28557115/answer ...