【POJ 2259】 Team Queue
【题目链接】
http://poj.org/problem?id=2259
【算法】
由题,一个人入队时,若这个人所在的组已经有人在队列中,则加入队列,否则排到队末
因此我们发现,这个队列一定是由连续的一组人的若干段组成,不妨用一个队列记录每组人的顺序,再分别将每组建一个队列
维护这(n+1)个队列即可,具体细节,笔者不再赘述
【代码】
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
#define MAXN 1010
#define MAXS 1000010 int i,n,s,x,pos,TC;
int g[MAXS];
bool inq[MAXN];
char opt[];
queue< int > ord;
queue< int > q[MAXN]; int main()
{ while (scanf("%d",&n) != EOF && n)
{
memset(inq,false,sizeof(inq));
while (!ord.empty()) ord.pop();
for (i = ; i <= n; i++)
{
while (!q[i].empty())
q[i].pop();
}
for (i = ; i <= n; i++)
{
scanf("%d",&s);
while (s--)
{
scanf("%d",&x);
g[x] = i;
}
}
printf("Scenario #%d\n",++TC);
while (true)
{
scanf("%s",&opt);
if (opt[] == 'S') break;
if (opt[] == 'E')
{
scanf("%d",&x);
if (inq[g[x]]) q[g[x]].push(x);
else
{
inq[g[x]] = true;
ord.push(g[x]);
q[g[x]].push(x);
}
}
if (opt[] == 'D')
{
pos = ord.front();
printf("%d\n",q[pos].front());
q[pos].pop();
if (q[pos].empty())
{
ord.pop();
inq[pos] = false;
}
}
}
printf("\n");
} return ; }
【POJ 2259】 Team Queue的更多相关文章
- 【UVA - 540】Team Queue (map,队列)
Team Queue Descriptions: Queues and Priority Queues are data structures which are known to most comp ...
- 【POJ 1112】Team Them Up!(二分图染色+DP)
Description Your task is to divide a number of persons into two teams, in such a way, that: everyone ...
- 【POJ 3071】 Football(DP)
[POJ 3071] Football(DP) Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4350 Accepted ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
随机推荐
- 搭建Cookie池
很多时候我们在对网站进行数据抓取的时候,可以抓取一部分页面或者接口,这部分可能没有设置登录限制.但是如果要抓取大规模数据的时候,没有登录进行爬取会出现一些弊端.对于一些设置登录限制的页面,无法爬取对于 ...
- 迷宫自动生成以及基于DFS的自动寻路算法
直接贴代码 #include<ctime> #include<conio.h> #include<iostream> #include<windows.h&g ...
- Vijos P1334 NASA的食物计划
解法 二维费用01背包问题 解法就是先枚举物品再枚举条件这里两个条件所以要枚举两个for 代码 #include <bits/stdc++.h> using namespace std; ...
- FileOutputStream将从一个文件中读取的内容写到另一个文件中
package com.janson.day2018082 import java.io.FileInputStream; import java.io.FileNotFoundException; ...
- 常用的HTTP测试工具谷歌浏览器插件汇总
网页的开发和测试时最常见的测试就是HTTP测试,作为曾经的测试人员在这方面还是略知一二的.其实做网页测试工作是非常繁琐的时期,有时候甚至是无聊重复的,如果没有网页测试工具的帮助的话,测试人员会越做越怀 ...
- HDU - 6446 Tree and Permutation
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6446 本题是一个树上的问题——DFS. 一棵N个结点的树,其结点为1~N.树具有N-1条边,每一条边具有 ...
- SSM+Shiro
1) 表名:用户表(Sys_Users) Salt:盐(佐料).为避免被黑客等进行攻击(暴力密码破解),所以一般在注册用户信息时,系统会随机生成一个随机码.在验证时会将密码和随机码进行运算,以验证密码 ...
- Display PowerPoint slide show within a VB form or control window
The example below shows how to use VB form/control as a container application to display a PowerPoin ...
- noip模拟赛 运
[问题背景]zhx 和妹子们玩数数游戏.[问题描述]仅包含 4 或 7 的数被称为幸运数.一个序列的子序列被定义为从序列中删去若干个数, 剩下的数组成的新序列.两个子序列被定义为不同的当且仅当其中的元 ...
- noip模拟赛 寻宝之后
题目背景 还记得NOIP2011的寻宝吗?6年之后,小明带着他的妹子小芳,再次走上了寻宝的道路. 然而这次他们寻宝回来之后,小明被困在了一个迷宫中. 题目描述 迷宫是一个n*m的字符矩阵. 小明在这个 ...