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 ...
随机推荐
- 百度ai 基于node 语音识别 音频文件类型转换
百度ai 基于node 语音识别 音频文件类型转换 项目简介 源代码移步:https://github.com/xuess/ai-baidu-node 本项目主要功能为,本地音频语音识别和文件类型转换 ...
- centos笔记-安装特定版本的mysql
centos6的yum默认安装的mysql是5.1版, 如果要安装5.6.16 版,有三个办法 1.yum方式, 这个方式的好处是通过yum安装卸载都很方便,坏处是版本无法详细制定,比如官方版本yum ...
- CentOS笔记-磁盘管理
Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 fdisk:用于磁盘分区 df [-ahikHTm] [目录或文件名] -a : ...
- 锁粒度 Deadlocks
锁粒度 MySQL :: MySQL 5.7 Reference Manual :: 14.5.2.4 Locking Reads https://dev.mysql.com/doc/refman/5 ...
- hdfs 3种 通讯协议
http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_design.html 通讯协议 所有的HDFS通讯协议都是建立在TCP/IP协议之上.客户端通过一个可配置的 ...
- NEU 1683: H-Index
题目描述 Given an array of citations (each citation is a non-negative integer) of a researcher, write a ...
- Oracle:通过pl/sql developer工具导入excel数据
1.在pl/sql developer中选择工具-->ODBC导入器 2.选择需要导入的EXCEL文件(CVS也可以):用户名.口令不用管,直接点“连接”,找到要导入的xls文件 3. 选择“导 ...
- 通用异步 Windows Socket TCP 客户端组件的设计与实现
编写 Windows Socket TCP 客户端其实并不困难,Windows 提供了6种 I/O 通信模型供大家选择.但本座看过很多客户端程序都把 Socket 通信和业务逻辑混在一起,剪不断理还乱 ...
- centos6.5下忘记mysql密码
1.此方式会使得服务器处于不安全的情况,请尽量保证在安全的环境下进行,因为,此方式,会使得任何人任意地连接MySQL数据库. 2.#vim /etc/my.cnf 在[mysqld]的段中,加上ski ...
- 收集几个Android CalendarView非常用属性
android:dateTextAppearance 设置日历View在日历表格中的字体皮肤;android:firstDayOfWeek 指定日历第一个星期的第一天,在日历中横向所在位置,从右边向左 ...