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 ...
随机推荐
- xamarin.android searchview的一些用法
前言 searchview是安卓常用的搜索控件,网上有很多关于searchview都是java的,所以我参看xamaroin官网的一些demo总结一些方法. 导读 1.如何创建一个searchview ...
- 正则工具类以及FinalClass
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/27811103 完整版见https://jadyer. ...
- (28)java web的hibernate使用
Hibernate是一个开放源代码的对象关系映射框架,它对JDBC进行了非常轻量级的对象封装,它将POJO与数据库表建立映射关系,是一个全自动的orm框架,hibernate可以自动生成SQL语句,自 ...
- EasyUI+Python-flask实现CRUD应用
1.需求分析 需求:应用easyui制作前端表格数据显示,flask制作后端路由 环境搭建略 2.easyui前端实现 2.1 easyui是前端实用的一个框架,这里我们要实现的是easyui的CRU ...
- seafile看不见repo报500错误的解决方法
环境 seafile-server-6.2.5 centos7.5 1804 现象 seafile服务器所在的VPS没动过,前一天seafile用还好好的,昨天客户端突然不能登录了,显示“服务器内部错 ...
- 【Codeforces 947B】 Producting Snow
[题目链接] 点击打开链接 [算法] 前缀和 + 堆 [代码] #include<bits/stdc++.h> using namespace std; typedef long long ...
- Linux网络编程笔记(修订版)
我的网络编程笔记, 因为最近又要做Linux下的网络编程,故重新修订, 其中一些内容参考了文末的链接及文章 1. 基本概念 2. 基本接口 2.1. 打开一个socket 2.2. 将 ...
- 【总结——HTTP协议】
一.HTTP协议简介 什么是HTTP?全称是HyperText Transfer Protocal,即:超文本传输协议,从1990年开始就在WWW上广泛应用,是现今在WWW上应用最多的协议,目前版本是 ...
- ASP.NET Core:创建一个Core项目
ylbtech-ASP.NET Core:创建一个Core项目 1.返回顶部 1. 2. 3. 4. 5. 2.返回顶部 1.新建Razor页面 2. 3. 4.Abc 4.1.Abc ...
- bzoj4516
后缀自动机 留个板子 upd:大概懂了 每次新加入的npRight集合肯定只有最后一个位置,那么求所有长得不一样的子串贡献就是Max-Min+1,因为Right集合只有这一个位置,所以这Max-Min ...