UVa 540 (团体队列) Team Queue
题意:
每个人都属于一个团体,在排队的时候,如果他所在的团体有人在队伍中,则他会站到这个团体的最后。否则站到整个队伍的队尾。
输出每次出队的人的编号。
分析:
容易看出,长队中,在同一个团体的人是排在一起的。
所以用两个队列模拟即可,一个队列保留团体的编号,另外一个队列数组存放的是团体中每个人的编号。
#include <cstdio>
#include <queue>
#include <map>
using namespace std; const int maxt = + ;
map<int, int> team;
char cmd[]; int main()
{
//freopen("in.txt", "r", stdin); int T, kase = ;
while(scanf("%d", &T) == && T)
{
printf("Scenario #%d\n", ++kase); for(int i = ; i < T; i++)
{
int n, x;
scanf("%d", &n);
while(n--) { scanf("%d", &x); team[x] = i; }
}
queue<int> q, q2[maxt]; //团体队列 和 q2[i]表示团体i中成员的队列 while(scanf("%s", cmd) == )
{
if(cmd[] == 'S') break;
if(cmd[] == 'E')
{
int x, t;
scanf("%d", &x);
t = team[x];
if(q2[t].empty()) q.push(t);
q2[t].push(x);
}
else if(cmd[] == 'D')
{
int t = q.front();
printf("%d\n", q2[t].front());
q2[t].pop();
if(q2[t].empty()) q.pop();
}
}
puts("");
} return ;
}
代码君
UVa 540 (团体队列) Team Queue的更多相关文章
- uva 540 - Team Queue(插队队列)
首发:https://mp.csdn.net/mdeditor/80294426 例题5-6 团体队列(Team Queue,UVa540) 有t个团队的人正在排一个长队.每次新来一个人时,如果他有队 ...
- UVA.540 Team Queue (队列)
UVA.540 Team Queue (队列) 题意分析 有t个团队正在排队,每次来一个新人的时候,他可以插入到他最后一个队友的身后,如果没有他的队友,那么他只能插入到队伍的最后.题目中包含以下操作: ...
- UVA 540 Team Queue(模拟+队列)
题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...
- 【UVA - 540】Team Queue (map,队列)
Team Queue Descriptions: Queues and Priority Queues are data structures which are known to most comp ...
- UVa 540 Team Queue 【STL】
题意:给出t个团体,这t个团体排在一起,每次新来一个x排队,如果在整个的团体队列中,有x的队友,那么x排在它的队友的后面,如果他没有队友,则排在长队的队尾 求给出的每一个出队命令,输出出队的人的编号 ...
- uva 540 (Team Queue UVA - 540)
又是一道比较复杂的模拟题.题中有两种队列,一种是总队列,从前向后.其他的是各个团体的小队列,因为入队的人如果有队友的话,会优先进入团体队列. 所以我们先设置两个队列和一个map,设置map倒是可以不用 ...
- Team Queue UVA - 540
Queues and Priority Queues are data structures which are known to most computer scientists. The Te ...
- Team Queue (uva540 队列模拟)
Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...
- Team Queue(多队列技巧处理)
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- 生成XML文件,通过实体生成XML文件
实体 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xm ...
- 关于count(1) 和 count(*)
Q:What is the difference between count(1) and count(*) in a sql queryeg.select count(1) from emp; an ...
- 【BZOJ 2440】[中山市选2011]完全平方数
Description 小 X 自幼就很喜欢数.但奇怪的是,他十分讨厌完全平方数.他觉得这些数看起来很令人难受.由此,他也讨厌所有是完全平方数的正整数倍的数.然而这丝毫不影响他对其他数的热爱. 这天是 ...
- dnf脚本的研究
[player number] 2 8 [pvp start area]0 0 0 00 0 0 00 0 0 0[dungeon]62[/dungeon][type] `[normal]`[gre ...
- linux whereis which
whereis 命令只能用于程序名的搜索,而且只搜索二进制文件(参数-b).man说明文件(参数-m)和源代码文件(参数-s). [root@localhost ~]# whereis svn svn ...
- OGRE1.8.1源码编译(VS2008)
最近在学习图形学,想看看OGRE源码,于是就去OGRE官网下载源码,配置环境,这里记录一下.鉴于电脑太破,VS2010比较慢,所以使用VS2008. 准备工作: CMake2.8 下载地址 ...
- QR code 金庸小说体(二)
传说 在二维码世纪,流传着这样一个传说,long long ago,武林一片混乱,这时魔教二长老创立了一门绝世武功——QR code,随后称霸武林.但同时也遭到武林中人的觊觎和反抗,各大武林正派掌门人 ...
- MySQL Replication 常用架构
转自: http://www.cnblogs.com/ggjucheng/archive/2012/11/13/2768879.html 前言 MySQLReplicaion本身是一个比较简单的架构, ...
- cf 357C
比赛的时候纯暴力超时了 看了别人的代码 set容器类做的 stl里还是有很多好东西的 /**************************************************** ...
- [BEC][hujiang] Lesson03 Unit1:Working life ---Grammar & Listening & Vocabulary
3 Working life p8 Grammar Gerund and infinitive(动名词和不定式) 一般而言: 1 动词后面接动名词还是不定式没有特定规则,主要取决于语言习 ...