浅谈队列:https://www.cnblogs.com/AKMer/p/10314965.html

题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1387

用\(t+1\)个队列,对于每个队伍用一个队列,然后用一个总队列存队伍之间的相对位置即可。

时间复杂度:\(O(m)\)

空间复杂度:\(O(n^2)\)

代码如下:

#include <cstdio>
using namespace std; const int maxn=2e3+5; int n;
char opt[20];
int bel[1000000]; int read() {
int x=0,f=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
return x*f;
} struct Team_Queue {
int list[maxn];
int head,tail; bool empty() {
return head==tail;
} void push_back(int x) {
list[tail++]=x;
} int pop() {
int res=list[head];
head++;return res;
}
}q[maxn]; void clear() {
for(int i=0;i<=n;i++)
q[i].head=q[i].tail=0;
} int main() {
int testcase=0;
while(1) {
n=read();if(!n)break;clear();
for(int i=1;i<=n;i++) {
int cnt=read();
for(int j=1,x;j<=cnt;j++)
x=read(),bel[x]=i;
}
printf("Scenario #%d\n",++testcase);
while(1) {
scanf("%s",opt+1);
if(opt[1]=='E') {
int x=read();
if(!q[bel[x]].empty())q[bel[x]].push_back(x);
else q[0].push_back(bel[x]),q[bel[x]].push_back(x);
}
if(opt[1]=='D') {
int id=q[0].list[q[0].head];
printf("%d\n",q[id].pop());
if(q[id].empty())q[0].pop();
}
if(opt[1]=='S')break;
}
puts("");
}
return 0;
}

HDU1387:Team Queue的更多相关文章

  1. UVA Team Queue

    版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u013840081/article/details/26180081 题目例如以下: Team Qu ...

  2. UVA 540 Team Queue(模拟+队列)

    题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...

  3. ACM学习历程——UVA540 Team Queue(队列,map:Hash)

    Description   Team Queue   Team Queue  Queues and Priority Queues are data structures which are know ...

  4. Team Queue(多队列技巧处理)

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

  5. hdu 1387(Team Queue) STL

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

  6. ACM题目————Team Queue

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

  7. HDU 1387 Team Queue

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

  8. Team Queue POJ - 2259 (队列)

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

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

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

随机推荐

  1. window.name跨域

    window.name? 每一个页面都有一个自己的window,而window.name是window的名字. window.name跨域原理 window对象有个name属性,该属性有个特征:即在一 ...

  2. uCOS-II的学习笔记(共九期)和例子(共六个)

    源:uCOS-II的学习笔记(共九期)和例子(共六个) 第一篇 :学习UCOS前的准备工作http://blog.sina.com.cn/s/blog_98ee3a930100w0eu.html 第二 ...

  3. 使用ASP.Net MVC5 Web API OData和Sencha Touch 开发WebAPP

    使用ASP.Net MVC5 Web API OData和SenCha Touch 开发WebAPP Demo 效果 第一步 创建数据库 创建表 第二步 搭建MVC,并导入OData 第三步,写入We ...

  4. 五、golang实现排序

    实现排序: 1.实现一个冒泡排序 2.实现一个选择排序 3.实现一个插入排序 4.实现一个快速排序 冒泡排序 package main import( "fmt" ) func b ...

  5. 容器rootfs

    挂载在容器根目录上.用来为容器进程提供隔离后执行环境的文件系统,就是所谓的“容器镜像”: 它还有一个更为专业的名称:rootfs (根文件系统). 所以,一个最常见的rootfs,或者说容器镜像,会包 ...

  6. 如何修改windows系统远程桌面默认端口

    此文档概述如何修改windows系统远程桌面的默认端口,众所周知windows系统默认的远程桌面端口是3389,这样对于开启远程桌面的计算机有一定的安全威胁,修改远程桌面的默认端口可以提高系统的安全性 ...

  7. 开机启动顺序rc.local与chkconfig的不同

    /etc/rc.local文件有如下两行/etc/init.d/mysql start/etc/init.d/keepalived start /etc/rc.local是按脚本的顺序一个启动后启动下 ...

  8. shell 读取文件的每一行内容并输出

    (1)#!/bin/bash while read linedo    echo $linedone < file (2)#!/bin/bash cat file  | while read l ...

  9. R语言笔记006——分组获取描述性统计量

    方法一:使用aggregate()分组获取描述性统计量 aggregate(mtcars[vars],by=list(am=mtcars$am),mean) aggregate(mtcars[vars ...

  10. spring boot: spring Aware的目的是为了让Bean获得Spring容器的服务

    Spring Aware的目的是为了让Bean获得Spring容器的服务 //获取容器中的bean名称import org.springframework.beans.factory.BeanName ...