题意:有若干个团体,每个团体有若干个元素,他们按次序来排队,如果队列中已经有同一团体的元素在,则可以插队到它后面,模拟这个过程

思路:用map存下元素与团体的关系,并开2个队列,一个存整体队伍的排列(毕竟同一个团体的元素会连在一起),另一个存每个团体内部的排列。

#include<cstdio>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
using namespace std;
int read(){
char ch=getchar();int f=,t=;
while (ch<''||ch>'') {if (ch=='-') f=-;ch=getchar();}
while (''<=ch&&ch<=''){t=t*+ch-'';ch=getchar();}
return t*f;
}
int main(){
int n,T=;
while (scanf("%d",&n)!=EOF&&n!=){
printf("Scenario #%d\n",++T);
map<int,int>mp;
for (int i=;i<=n;i++){
int x=read();
while (x--){
mp[read()]=i;
}
}
queue<int> qAll,qTeam[];
char s[];
scanf("%s",s);
while (s[]!='S'){
if (s[]=='E'){
int x=read();
int y=mp[x];
if (qTeam[y].empty()) qAll.push(y);
qTeam[y].push(x);
}else if (s[]=='D'){
int x=qAll.front();
printf("%d\n",qTeam[x].front());qTeam[x].pop();
if (qTeam[x].empty()) qAll.pop();
}
scanf("%s",s);
}
printf("\n");
}
}

Team Queue(POJ 2259)的更多相关文章

  1. Team Queue POJ - 2259 (队列)

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  2. queue POJ 2259 Team Queue

    题目传送门 题意:先给出一些小组成员,然后开始排队.若前面的人中有相同小组的人的话,直接插队排在同小组的最后一个,否则只能排在最后面.现在有排队和出队的操作. 分析:这题关键是将队列按照组数分组,用另 ...

  3. POJ 2259 - Team Queue - [队列的邻接表]

    题目链接:http://poj.org/problem?id=2259 Queues and Priority Queues are data structures which are known t ...

  4. poj 2259 Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2977   Accepted: 1092 Descri ...

  5. POJ 2259 Team Queue(队列)

    题目原网址:http://poj.org/problem?id=2259 题目中文翻译: Description 队列和优先级队列是大多数计算机科学家已知的数据结构. 然而,Team Queue并不是 ...

  6. hdu 1387(Team Queue) STL

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  7. Team Queue (uva540 队列模拟)

    Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...

  8. ACM题目————Team Queue

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  9. HDU 1387 Team Queue

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. 从零开始PHP攻略(001)——Bob的汽车零部件商店

    1.创建订单表单 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...

  2. 我用.htaccess做了些什么?

    1.防图片盗链,减轻流量压力: 2.index.php 301转向到域名,有利于PR权重集中: 3.其它还不会,慢慢来…… 我是如何做的? <IfModule mod_rewrite.c> ...

  3. 应用程序有bug崩溃重启的案例2

    ------解决思路----------------------另外做一个服务或者程序定时监控系统进程.程序奔溃的话,都会在入口函数出现异常处理一下winform可以有两个事件来捕获主线程异常和线程异 ...

  4. windows下tomcat在当前窗口运行,不在新弹出的窗口运行

    window下tomcat在当前窗口启动,不在一个新的窗口启动startup.bat中最下几行goto setArgs:doneSetArgscall "%EXECUTABLE%" ...

  5. 【linux】su和sudo命令的区别

    来源:http://www.jb51.net/LINUXjishu/12713.html 一. 使用 su 命令临时切换用户身份 1.su 的适用条件和威力 su命令就是切换用户的工具,怎么理解呢?比 ...

  6. Spring Boot with Docker

    翻译自:https://spring.io/guides/gs/spring-boot-docker/ Spring Boot with Docker 这篇教程带你一步步构建一个Docker镜像用来运 ...

  7. LeetCode解题报告—— 4Sum & Remove Nth Node From End of List & Generate Parentheses

    1. 4Sum Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + ...

  8. Spiral Matrix I&&II

    Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral or ...

  9. ASP.NET MVC5(一)—— URL路由

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  10. 前端读者 | 嗨,你知道this吗

    本文来自 @position_柚子,地址:https://juejin.im/post/5995c7a76fb9a0247a60c407 在平时的代码中,相信大家经常用到 this,可是你真的明白此 ...