hdu 1387(Team Queue) STL
Team Queue
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2051 Accepted Submission(s): 713
In a team queue each element belongs to a team. If an element enters the queue, it first searches the queue from head to tail to check if some of its teammates (elements of the same team) are already in the queue. If yes, it enters the queue right behind them. If not, it enters the queue at the tail and becomes the new last element (bad luck). Dequeuing is done like in normal queues: elements are processed from head to tail in the order they appear in the team queue.
Your task is to write a program that simulates such a team queue.
Finally, a list of commands follows. There are three different kinds of commands:
ENQUEUE x - enter element x into the team queue
DEQUEUE - process the first element and remove it from the queue
STOP - end of test case
The input will be terminated by a value of 0 for t.
3 101 102 103
3 201 202 203
ENQUEUE 101
ENQUEUE 201
ENQUEUE 102
ENQUEUE 202
ENQUEUE 103
ENQUEUE 203
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
2
5 259001 259002 259003 259004 259005
6 260001 260002 260003 260004 260005 260006
ENQUEUE 259001
ENQUEUE 260001
ENQUEUE 259002
ENQUEUE 259003
ENQUEUE 259004
ENQUEUE 259005
DEQUEUE
DEQUEUE
ENQUEUE 260002
ENQUEUE 260003
DEQUEUE
DEQUEUE
DEQUEUE
DEQUEUE
STOP
0
101
102
103
201
202
203
Scenario #2
259001
259002
259003
259004
259005
260001
1、进队:
用map匹配先队列中有没有你的term,有的话在你排在 term最后,没有的话新建term,并排在整体最后;
//608MS 4544K 1051B G++
#include<iostream>
#include<algorithm>
#include<string.h>
#include<queue>
#include<map>
#include<vector>
using namespace std;
const int N = ;
typedef queue<int> INTQ; int main()
{
int n,m,a;
char op[];
int cas=;
while(cin>>n && n){
map<int ,int>TERM;
for(int i=;i<=n;i++){
cin>>m;
for(int j=;j<m;j++){
cin>>a;
TERM[a]=i;
}
} INTQ V[N];
map<int, int>M2V;
int index=;
int head_index=index;
cout<<"Scenario #"<<cas++<<endl;
while(cin>>op){
if(strcmp(op, "STOP")==){
break;
}
else if(strcmp(op, "ENQUEUE")==){
cin>>a;
if(M2V[TERM[a]]==){
INTQ tQ;
tQ.push(a);
V[index] = tQ;
M2V[TERM[a]] = index;
index = (index+)%N;
}else{
V[M2V[TERM[a]]].push(a);
} }else{
int a=V[head_index].front();
V[head_index].pop();
cout<<a<<endl;
if(V[head_index].empty()){
M2V[TERM[a]] = ;
head_index = (head_index+)%N;
}
} }
cout<<endl;
}
return ;
}
hdu 1387(Team Queue) STL的更多相关文章
- Bomb HDU - 3555 (数位DP)
Bomb HDU - 3555 (数位DP) The counter-terrorists found a time bomb in the dust. But this time the terro ...
- 优先队列(Priority Queue)
优先队列(Priority Queue) A priority queue must at least support the following operations: insert_with_pr ...
- c/c++ linux 进程间通信系列6,使用消息队列(message queue)
linux 进程间通信系列6,使用消息队列(message queue) 概念:消息排队,先进先出(FIFO),消息一旦出队,就从队列里消失了. 1,创建消息队列(message queue) 2,写 ...
- 消息队列(Message Queue)简介及其使用
消息队列(Message Queue)简介及其使用 摘要:利用 MSMQ(Microsoft Message Queue),应用程序开发人员可以通过发送和接收消息方便地与应用程序进行快速可靠的通信.消 ...
- Java分布式:消息队列(Message Queue)
Java分布式:消息队列(Message Queue) 引入消息队列 消息,是服务间通信的一种数据单位,消息可以非常简单,例如只包含文本字符串:也可以更复杂,可能包含嵌入对象.队列,是一种常见的数据结 ...
- 优先队列——二项队列(binominal queue)
[0]README 0.1) 本文文字描述部分转自 数据结构与算法分析, 旨在理解 优先队列——二项队列(binominal queue) 的基础知识: 0.2) 本文核心的剖析思路均为原创(inse ...
- Linux等待队列(Wait Queue)
1. Linux等待队列概述 Linux内核的等待队列(Wait Queue)是重要的数据结构,与进程调度机制紧密相关联,可以用来同步对系统资源的访问.异步事件通知.跨进程通信等.在Linux中,等待 ...
- 线段树扫描线(一、Atlantis HDU - 1542(覆盖面积) 二、覆盖的面积 HDU - 1255(重叠两次的面积))
扫描线求周长: hdu1828 Picture(线段树+扫描线+矩形周长) 参考链接:https://blog.csdn.net/konghhhhh/java/article/details/7823 ...
- HDU 5510---Bazinga(指针模拟)
题目链接 http://acm.hdu.edu.cn/search.php?action=listproblem Problem Description Ladies and gentlemen, p ...
随机推荐
- 查看Oracle加锁情况及解锁方法
注意:必须有Oracle DBA 权限才能操作一下SQL语句: ---查询锁定的会话 select * from v$session t where t.SID in (select t2.sessi ...
- java socket 通讯
(转)http://blog.csdn.net/xn4545945/article/details/8098646
- Jsoup使用随记
这段时间工作比较空闲,在网上找资料学习的时候看到数据抓取这一块,来了兴趣 用jsoup实现数据抓取着实方便,唯一美中不足的是官方API是英文版的,对我这样英语水平不好的程序员来说着实困扰,只能一点点的 ...
- Maven多环境打包
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- java 工具类
首先把构造函数设置为私有.然后方法都改为静态.
- mysql数据引擎的概念介绍
什么是数据库引擎?每种数据库的数据格式,内部实现机制都是不同的,要利用一种开发工具访问一种数据库,就必须通过一种中介程序,这种开发工具与数据库之间的中介程序就叫数据库引擎. 如果你是个赛车手并且按一下 ...
- java自编时间工具类
package timeTools; import java.text.ParseException; import java.text.SimpleDateFormat; import java.u ...
- Nginx 和 PHP的安装配置
1.安装PHP(注意系统默认安装了php,要安装高版本之前最好卸载旧版本,因为这个原因纠结了四个小时) ./configure \ --prefix=/usr/local/php \ --exec-p ...
- 第一二九天上课 PHP 自制简单开发模板
构建基础架构 在项目文件夹(自定义)下创建 (1)核心目录:WQ (2)模板目录:MoBan (3)编译目录:BianYi (4)创建配置文件: config.ini.php <?php //获 ...
- truncate table和delete table 的区别
truncate table和不带 where 的 detele 功能一样,都是删除表中的所有数据. 但TRUNCATE TABLE 速度更快,占用的日志更少,这是因为 TRUNCATE TABLE ...