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 ...
随机推荐
- 2018-2019-1 20165330 《信息安全系统设计基础》第六周课上测试ch02&课下作业
课上测试 测试-3-ch02 任务详情 编写一个程序 "week0203学号.c",运行下面代码: 1 short int v = -学号后四位 2 unsigned short ...
- 设计模式之——Builder建造模式
Builder模式又叫建造模式,是用于组装具有复杂结构的实例的模式. 示例程序是编写一个文档,并且写入到文件中,该文档具有以下结构,含有标题,字符串,一些条目. Builder抽象类,为建造模式的核心 ...
- LeetCode_Isomorphic Strings
Isomorphic Strings Given two strings s and t, determine if they are isomorphic. Two strings are isom ...
- ubuntu 编辑pdf
参考:https://www.2cto.com/kf/201710/689121.html Ubuntu下几个功能比较全面的PDF编辑工具. 1.flpsed flpsed是一个WYSIWYG的“伪” ...
- JS代码识别扫码设备
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- python学习笔记(四)random 、json模块
一.模块简介 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句. 导入模块 import module #导入模块 f ...
- 《Oracle RAC性能优化》
一 RAC环境 RAC架构,2节点信息 节点1 SQL> show parameter instance NAME TYPE ...
- 工作笔记——js与文件上传下载
1 js判断上传文件的后缀名,文件大小 //判断照片大小 function getPhotoSize(obj){ photoExt=obj.value.substr(obj.value.lastInd ...
- Linux系统——日志文件
日志文件的分类 (1)内核及系统日志 由系统服务rsyslog管理,根据去主配置文件/etc/rsyslog.conf中的设置决定将内核消息及各种系统程序消息记录到什么位置. /etc/rsyslog ...
- obj比较
<script> var obj1={name:'one',age:30}; var obj2={name:'one',age:30}; //比较两个字符串对象的[值]是否相等 Objec ...