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 ...
随机推荐
- pip China
建个文件 ~/.pip/pip.conf, 内容如下 [global] index-url = http://b.pypi.python.org/simple [install] use-mirror ...
- shell 命令集
shell 常用知识点--------------------------------------- sed 用法 http://www.cnblogs.com/edwardlost/archive/ ...
- Java值传递以及引用的传递、数组的传递!!
转(http://blog.csdn.net/niuniu20008/article/details/2953785) 许多编程语言都有2种方法将参数传递给方法------按值传递和按引用传递. 与其 ...
- c# 利用结构体获取json数据
最近做微信支付,要获取用户的openid,调用接口后返回的是json格式的数据,我想在c#后台把数据逐一取出,网上查了查,找到以下方法: 1.首先调用接口,要有一个post数据到指定url并返回数据的 ...
- 2016-11-10:win7下VMware虚拟机中CentOS6.5网络配置
在win7环境下,使用桥接和NAT模式配置VMware虚拟机网络,实现宿主机与虚拟机以及虚拟机通过宿主机网卡访问互联网. 1 配置VMware虚拟网络编辑器 VMnet0 桥接模式 VMnet1仅主机 ...
- wordpress stratus模板使用 产品显示问题
产品不显示,只显示展示产品代码. 1.研究原站demo,思考产品展示调用自woocommerce. 2.查看woocommerce文档,更新展示代码. 3.修改后产品出现,但是多余的关联推荐也展示出来 ...
- 官方提供的屏蔽百度转码Baidu Transcoder的方法no-transform
首先,百度在官方的声明中说:[喝小酒的网摘]http://blog.hehehehehe.cn/a/17112.htm百度仅作为中立的转码工具及相关技术的提供方.在转码过程中,百度对第三方网站内容不做 ...
- Drools规则
1.实现业务逻辑和业务规则的分离,实现业务规则的集中管理 2.可以动态的改变业务规则,从而快速响应需求变更 3.业务分析人员也可以参与编辑.维护系统的业务规则 fact:一个普通的JavaBean插入 ...
- 利用JAVA生成二维码
本文章整理于慕课网的学习视频<JAVA生成二维码>,如果想看视频内容请移步慕课网. 维基百科上对于二维码的解释. 二维条码是指在一维条码的基础上扩展出另一维具有可读性的条码,使用黑白矩形图 ...
- MySQL For Windows Zip解压版安装
前言 Windows 下 MySQL 有msi和zip解压安装版两种,而zip版只需解压并做简单配置后就能使用,我个人比较喜欢这种方式. 注意我们这里说的MySQL是指MySQL服务器,有很多初学的同 ...