poj-2259 team queue(数据结构)
第一遍看的时候立即想到了哈希表。
再想时觉得两个队列,一个用来排队伍之间的顺序,一个用来排队伍内部成员的顺序即足够了。
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(数据结构)的更多相关文章
- poj 2259 Team Queue
Team Queue Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2977 Accepted: 1092 Descri ...
- POJ 2259 Team Queue(队列)
题目原网址:http://poj.org/problem?id=2259 题目中文翻译: Description 队列和优先级队列是大多数计算机科学家已知的数据结构. 然而,Team Queue并不是 ...
- POJ 2259 - Team Queue - [队列的邻接表]
题目链接:http://poj.org/problem?id=2259 Queues and Priority Queues are data structures which are known t ...
- (队列的应用5.3.2)POJ 2259 Team Queue(队列数组的使用)
/* * POJ_2259.cpp * * Created on: 2013年10月30日 * Author: Administrator */ #include <iostream> # ...
- queue POJ 2259 Team Queue
题目传送门 题意:先给出一些小组成员,然后开始排队.若前面的人中有相同小组的人的话,直接插队排在同小组的最后一个,否则只能排在最后面.现在有排队和出队的操作. 分析:这题关键是将队列按照组数分组,用另 ...
- Team Queue POJ - 2259 (队列)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- hdu 1387(Team Queue) STL
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue (uva540 队列模拟)
Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...
- ACM题目————Team Queue
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- HDU 1387 Team Queue
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- mysql状态分析之show global status
这里整理下mysql global status的相关命令,在计算监控数据的时候需要用到 一.慢查询 show variables like '%slow%'; +------------------ ...
- .c和.h的联系
.c文件就是C语言系列的源文件,而H文件则是C语言的头文件,即C系列中存放函数和全局变量的文件,因为C中的函数是被封装起来的,即无法看到其代码. 子程序不要定义在*.h中.函数定义要放在*.c中,而* ...
- $obj->0
w对象 数组 分别对内存的 消耗 CI result() This method returns the query result as an array of objects, or an empt ...
- 属性attribute和property的区别
<!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...
- Allocation-Free Collections(在堆栈上使用内存)
假设你有一个方法,通过创建临时的List来收集某些数据,并根据这些数据来统计信息,然后销毁这个临时列表.这个方法被经常调用,导致大量内存分配和释放以及增加的内存碎片.此外,所有这些内存管理都需要时间, ...
- python重建二叉树
# -*- coding:utf-8 -*- # class TreeNode: # def __init__(self, x): # self.val = x # self.left = None ...
- 3.Github介绍
很多人都知道,Linus在1991年创建了开源的Linux.从此,Linux系统不断发展,已经成为最大的服务器系统软件了.Linus虽然创建了Linux,但Linux的壮大是靠全世界热心的志愿者参与的 ...
- H5开发APP入门
一.MUI MUI是一个最接近原生APP体验的高性能前端框架.我们用它来排版布局. 官方网站:http://dev.dcloud.net.cn/mui/ 二.HTML5PLUS html5+是HBul ...
- JS生成随机字符串的多种方法
这篇文章主要介绍了JS生成随机字符串的方法,需要的朋友可以参考下 下面的一段代码,整理电脑时,记录备查. <script language="javascript"> ...
- usb-tooltip 重写.tooltip { word-break: break-all; }解决单词内换行
<div style="padding: 5px 10px; font-size: 16px; text-align: left" class="truncate& ...