queue POJ 2259 Team Queue
题意:先给出一些小组成员,然后开始排队。若前面的人中有相同小组的人的话,直接插队排在同小组的最后一个,否则只能排在最后面。现在有排队和出队的操作。
分析:这题关键是将队列按照组数分组,用另外一个队列保存组的序号,当该组里没有人了才换下一组。很好的一道题。
收获:队列的灵活运用
代码:
/************************************************
* 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的更多相关文章
- 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> # ...
- Team Queue POJ - 2259 (队列)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- Team Queue(POJ 2259)
题意:有若干个团体,每个团体有若干个元素,他们按次序来排队,如果队列中已经有同一团体的元素在,则可以插队到它后面,模拟这个过程 思路:用map存下元素与团体的关系,并开2个队列,一个存整体队伍的排列( ...
- 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 ...
- poj 3841 Double Queue (AVL树入门)
/****************************************************************** 题目: Double Queue(poj 3481) 链接: h ...
随机推荐
- label 对齐
<label for="username">用户名</label> <input type="text" id="use ...
- Arcgis Engine(ae)接口详解(5):IGeometry几何基础操作
//点操作~~~~~~~~~~~~~~~~~~~~~~~~~ //通过坐标生成点 IPoint point = new PointClass(); point.PutCoords(, ); //获取点 ...
- Hadoop之HDFS文件操作
摘要:Hadoop之HDFS文件操作常有两种方式.命令行方式和JavaAPI方式.本文介绍怎样利用这两种方式对HDFS文件进行操作. 关键词:HDFS文件 命令行 Java API HD ...
- 事件序列化器 Flume 的无数据丢失保证,Channel 和事务
小结: 1.Flume 的持久性保证依赖于使用的持久性Channel 的保证 通过事件序列化器将Flume事件转化为外部存储格式 主要的事件序列化器: 1.文本 2.带有头信息的文本 3.Avro序列 ...
- C++使用模板、函数指针、接口和lambda表达式这四种方法做回调函数的区别比较
在C++中,两个类之间存在一种关系,某个类需要另外一个类去完成某一个功能,完成了之后需要告知该类结果,这种最普通最常见的需求,往往使用回调函数来解决. 如题,我总结下来有这么四种方式可以完成这项功能, ...
- STM32的低功耗设置
因为产品需求,系统功耗是一个很重要的考虑方面.好好看下STM32F103的低功耗问题,以便编写驱动. 1.STM32的电源 1.1 STM32电源框图 上面的电源中需要注意的是后备供电区域,这个部分由 ...
- powerdesigner 导入mysql数据库(步骤及注意点)
参考博客 PowerDesigner中导入MYSQL数据库结构的步骤 mysql ODBC 在64位下提示找不到odbc驱动问题 PowerDesigner逆向工程导入MYSQL数据库总结
- DataSnap的如果网络断线,如何恢复?
timer代码很简单:var adbsevertime :TDateTime;begin try adbsevertime := ClientModule1.ServerMethods1Client. ...
- 代码块、继承、this、super、final(java基础知识八)
1.代码块的概述和分类 * A:代码块概述 * 在Java中,使用{}括起来的代码被称为代码块.* B:代码块分类 * 根据其位置和声明的不同,可以分为局部代码块,构造代码块,静态代码块,同步代码块( ...
- code::Blocks 汉化经验
首先,在网上下载一个code::Block的汉化包 code::Block汉化包下载地址,复制到地址栏即可. http://files.cnblogs.com/files/QW-lzm/codebl ...