题目传送门

题意:先给出一些小组成员,然后开始排队。若前面的人中有相同小组的人的话,直接插队排在同小组的最后一个,否则只能排在最后面。现在有排队和出队的操作。

分析:这题关键是将队列按照组数分组,用另外一个队列保存组的序号,当该组里没有人了才换下一组。很好的一道题。

收获:队列的灵活运用

代码:

/************************************************
* Author :Running_Time
* Created Time :2015/9/9 星期三 14:37:14
* File Name :M.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e3 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
queue<int> id;
queue<int> num[N];
map<int, int> mp;
bool inq[N];
char op[11];
int n; void init(void) {
while (!id.empty ()) id.pop ();
for (int i=1; i<=n; ++i) {
while (!num[i].empty ()) num[i].pop ();
}
memset (inq, false, sizeof (inq));
mp.clear ();
} int main(void) {
int cas = 0;
while (scanf ("%d", &n) == 1) {
if (!n) break;
init ();
if (cas) puts ("");
printf ("Scenario #%d\n", ++cas);
int x;
for (int i=1; i<=n; ++i) {
int m; scanf ("%d", &m);
for (int j=1; j<=m; ++j) {
scanf ("%d", &x);
mp[x] = i;
}
}
scanf ("%s", &op);
while (strcmp (op, "STOP")) {
if (strcmp (op, "ENQUEUE") == 0) {
scanf ("%d", &x);
if (!inq[mp[x]]) {
inq[mp[x]] = true;
id.push (mp[x]);
}
num[mp[x]].push (x);
}
else {
if (id.empty ()) continue;
int fir = id.front ();
printf ("%d\n", num[fir].front ()); num[fir].pop ();
if (num[fir].empty ()) {
inq[fir] = false; id.pop ();
}
}
scanf ("%s", &op);
}
} return 0;
}

  

queue 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. Team Queue POJ - 2259 (队列)

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

  6. Team Queue(POJ 2259)

    题意:有若干个团体,每个团体有若干个元素,他们按次序来排队,如果队列中已经有同一团体的元素在,则可以插队到它后面,模拟这个过程 思路:用map存下元素与团体的关系,并开2个队列,一个存整体队伍的排列( ...

  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. poj 3841 Double Queue (AVL树入门)

    /****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...

随机推荐

  1. scala快速学习笔记(二):控制结构,类和对象

    IV.控制结构 1.if/else 除基本用法外,if/else语句能用来赋值,进而代替?:运算符.这得益于在Scala中,每个语句块都有值,就是该语句块最后一个语句的值.请看下面的代码. def a ...

  2. ES6常用语法简介import export

    ES6常用语法简介import export let与var用法区别 //var var a = []; for (var i = 0; i < 10; i++) { a[i] = functi ...

  3. python day-01 (python基础知识1)

    1.计算机组成(参与运算的) 主板+CPU+内存 2.python 简史 解释型语言,弱类型语言(eg:a 可以表示很多意思   a=1  或 a = “小红”) 3.数据类型: int(整数类型): ...

  4. 用 nodejs 写一个命令行工具 :创建 react 组件的命令行工具

    用 nodejs 写一个命令行工具 :创建 react 组件的命令行工具 前言 上周,同事抱怨说 react 怎么不能像 angular 那样,使用命令行工具来生成一个组件.对呀,平时工作时,想要创建 ...

  5. GPS格式标准

    GPS接收机串行通信标准摘要 参考NMEA-0183 美国国家海洋电子协会(NMEA—The NationalMarine Electronics Association) 为了在不同的GPS导航设备 ...

  6. 数据结构之 栈与队列--- 走迷宫(深度搜索dfs)

    走迷宫 Time Limit: 1000MS Memory limit: 65536K 题目描述 一个由n * m 个格子组成的迷宫,起点是(1, 1), 终点是(n, m),每次可以向上下左右四个方 ...

  7. html5--3.2 input元素(2)

    html5--3.2 input元素(2) 学习要点 input元素及其属性 input元素 用来设置表单中的内容项,比如输入内容的文本框,按钮等 不仅可以布置在表单中,也可以在表单之外的元素使用 i ...

  8. html5--6-47 阶段练习2-渐变按钮

    html5--6-47 阶段练习2-渐变按钮 实例 @charset="UTF-8"; .but1{ padding: 10px 20px; font-size:16px; tex ...

  9. 安卓开发eclipse如何导出项目

    安卓开发如何导出项目 方法/步骤   1 首先打开eclipse 2 选择file然后选择export 3 选择android application 4 点击next 5 选择项目browse可以更 ...

  10. Code-NFine:下来框和复选框

    ylbtech-Code-NFine:下来框和复选框 1.返回顶部 1. 1.1 html $("#F_OrganizeId").bindSelect({ url: "/ ...