【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 ...
随机推荐
- 手机中快速看图,浏览编辑DWG 梦想极光CAD
梦想极光CAD6.0(2016.3.1) 手机版最新更新 1.增加手机上,图纸浏览时预览功能 2.增加直接从手机,QQ接收目录下加载文件功能 3.手机交互界面优化 4.增加新建图纸功能 5.增加缓存功 ...
- CAD控件:QT开发使用控件入门
1. 环境搭建: 3 1.1. 安装Qt 3 1.2. 安装Microsoft Windows SDK的调试包 6 2. QT中使用MxDraw控件 7 1.3. 引入控件 7 3. 打开DWG文件 ...
- go new() 和 make() 的区别
看起来二者没有什么区别,都在堆上分配内存,但是它们的行为不同,适用于不同的类型. new(T) 为每个新的类型T分配一片内存,初始化为 0 并且返回类型为*T的内存地址:这种方法 返回一个指向类型为 ...
- tab下拉显示
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8 ...
- 类模板成员函数默认值问题:an out-of-line definition of a member of a class template cannot have default arguments
template <typename T> class A { ); }; template<typename T> ) { /* */ } 对于类似上文代码,VS编译器会报 ...
- <MyBatis>入门四 传入的参数处理
1.单个参数 传入单个参数时,mapper文件中 #{}里可以写任意值 /** * 传入单个参数 */ Employee getEmpById(Integer id); <!--单个参数 #{} ...
- (七)python3 切片
切片:取一个 list 或 tuple 的部分元素是非常常见的操作 >>> L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack'] #笨办法 ...
- 复习1背包dp
背包问题是对于一个有限制的容器,一般计算可以装的物品的价值最值或数量.通常每个物品都有两个属性空间和价值,有时还有数量或别的限制条件,这个因体而异. 背包大概分成3部分,下面会细述这最经典的3种题型 ...
- [kuangbin带你飞]专题五 并查集 A - Wireless Network
An earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wi ...
- Linux查看设备信息命令
系统 #查看内核/操作系统/CPU信息 uname -a #查看操作系统版本 head -n 1 /etc/issue #查看CPU信息 cat /proc/cpuinfo #查看计算机名 hostn ...