HDU1387:Team Queue
浅谈队列: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的更多相关文章
- UVA Team Queue
版权声明:本文为博主原创文章.未经博主同意不得转载. https://blog.csdn.net/u013840081/article/details/26180081 题目例如以下: Team Qu ...
- UVA 540 Team Queue(模拟+队列)
题目代号:UVA 540 题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page ...
- ACM学习历程——UVA540 Team Queue(队列,map:Hash)
Description Team Queue Team Queue Queues and Priority Queues are data structures which are know ...
- Team Queue(多队列技巧处理)
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- hdu 1387(Team Queue) STL
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- ACM题目————Team Queue
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- HDU 1387 Team Queue
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue POJ - 2259 (队列)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- POJ 2259 - Team Queue - [队列的邻接表]
题目链接:http://poj.org/problem?id=2259 Queues and Priority Queues are data structures which are known t ...
随机推荐
- ubuntu没有声音解决办法
cd /usr/lib/dbus-1.0/ chmod +x dbus-daemon-launch-helper sudo gpasswd -a $USER audio sudo killall pu ...
- iOS_多线程(一)
在学习多线程之前首先搞清楚以下几个问题. 并发:在同一时刻,只有一条指令被执行,多条指令进行快速切换执行. 并行:在同一时刻,多个处理器可以处理多条指令 1.什么是进程? 一个运行的程序就是 ...
- Python 字符串概念和操作
# 字符串概念:由单个字符串组成的一个集合 # 普通字符串(非原始字符串) str = "abc" print(str) # abc # 原始字符串(前面加r) str = r&q ...
- 在Visual Studio中使用VueJS时,不可以用 v-bind 的简写 : 及 v-on的简写 @
在Visual Studio中使用VueJS时,不可以用 v-bind 的简写 : 及 v-on的简写 @ 一方面 @符号和 Razor引擎冲突, 另外,当使用VS的格式化代码功能时, 会把 html ...
- yum 源配置
在 /etc/yum.repos.d 下建立一个 .repo 文件 vim yum.repo [cd] name=cd baseurl=file:///run/media/root/RHEL-7.0 ...
- FreeMarker缓存处理
FreeMarker 的缓存处理主要用于模版文件的缓存,一般来讲,模版文件改动不会很频繁,在一个流量非常大的网站中,如果频繁的读取模版文件对系统的负担还是很重的,因此 FreeMarker 通过将模版 ...
- cuffdiff problem--Performed 0 isoform-level transcription difference tests
如何解决cuffdiff运行结果中表达量为0的情况? cuffdiff -o cdiffout -b ref.fasta -u -p 15 --library-type fr-firststrand ...
- vs 2010 mvc 3.0安装软件
下载链接如下:MVC 3安装包:http://www.microsoft.com/downloads/zh-cn/details.aspx?familyid=d2928bc1-f48c-4e95-a0 ...
- mysql基础(1)-基本操作
数据库 数据库(Database,DB)是数据的集合,是一个长期存储在计算机内的.有组织的.有共享的.统一管理的数据集合. 存储数据 管理数据 数据库类型 关系型数据库:由二维表及其之间的联系组成的一 ...
- 如何在myEclipse中创建配置文件,比如:XXX.properties
myEclipse是没有直接生成配置文件的方法,除非去配置某些插件. 目前通用的方法是:随便新建一个文件(比如:XXX.xml),然后对该文件重命名,改成XXX.properties即可. 很简单有没 ...