浅谈队列: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. PHP连接到mysql的方法--mysqli和PDO

    php连接到mysql数据库,经典的方式就是使用mysql_connect(),具体代码如下: mysql_connect($db_host, $db_user, $db_pass) or die(m ...

  2. GPU的工作原理

    转:https://blog.csdn.net/p23onzq/article/details/79609629 在GPU出现以前,显卡和CPU的关系有点像“主仆”,简单地说这时的显卡就是画笔,根据各 ...

  3. vector对象

    vector是模板而非类型,由vector生成的类型必须包含vector中元素的类型,例如vector<int> 定义和初始化vector对象: vector<T> v1    ...

  4. CodeWars上的JavaScript技巧积累

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice The sli ...

  5. apache实现http自动转为https

    1.确认此服务器apache已经配置过证书可以用https访问到 2.确认/etc/apache2/ports.conf 下有 Listen 80Listen 443(此条) 3.配置虚礼主机定将域名 ...

  6. Python中的exec、eval的区别

    通过exec可以执行动态Python代码,类似Javascript的eval功能: 而Python中的eval函数可以计算Python表达式,并返回结果: (exec不返回结果,print(eval( ...

  7. MySql基础学习-总纲

  8. php:PHP解析xml的4种方法

    XML处理是开发过程中经常遇到的,PHP对其也有很丰富的支持,本文只是对其中某几种解析技术做简要说明,包括:Xml parser, SimpleXML, XMLReader, DOMDocument. ...

  9. Codeforces 610D Vika and Segments 线段树+离散化+扫描线

    可以转变成上一题(hdu1542)的形式,把每条线段变成宽为1的矩形,求矩形面积并 要注意的就是转化为右下角的点需要x+1,y-1,画一条线就能看出来了 #include<bits/stdc++ ...

  10. python后端面试题

    1. 果壳 电话面试: 说一下TCP的三次握手,四次挥手,为什么会这样? http安全的性的了解,说一下对cookie和session的了解: 对mysql的了解,说一下你常用的数据类型,char和v ...