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 ...
随机推荐
- 关于dispatch_semaphore的使用
dispatch_semaphore是GCD用来同步的一种方式,与他相关的共有三个函数,分别是 dispatch_semaphore_create,dispatch_semaphore_signal, ...
- 20145239杜文超《网络攻防》- MSF基础应用
20145239杜文超<网络攻防>- MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit:实现攻击行为的主体,但没有载荷只 ...
- Mybatis细节问题
1.将字符串转换为日期格式? @DateTimeFormat(pattern="yyyy-MM-dd")
- 关于view里面xib的问题
[[[NSBundle mainBundle] loadNibNamed:@"NetFailView" owner:self options:nil] lastObject]; 会 ...
- EF Code-First 学习之旅 继承策略
Code First中有三种不同的方法表示继承层次关系 1.Table per Hierarchy (TPH): 这种方法建议用一个表来表示整个类的继承层次关系,表中包含一个识别列来区分继承类,在En ...
- linux基础(3)-java安装
安装jdk1.8 [root@spark1 usr]# mkdir java #创建java目录 通过WinSCP将jdk-8u77-linux-x64.tar.gz传到/usr/java目录下 [r ...
- this和super用法
1. this能分清混淆,形参名与当前对象的某个成员有相同的名字,需要明确使用this关键字来指明你要使用某个成员,使用方法是“this.成员名”. 一般以this.形参数名=形参名,代表送进来赋值的 ...
- 添加vue调试工具vue-devtolls
1.在使用脚手架vue-cli.js下载好node-modules 2.在node-modules目录下找的vue-devtools文件(如果没有可以用npm install vue-devtools ...
- 获取浏览器的相关信息(navigator)
* 智能机浏览器版本信息: * */ var browser = { versions: function() { var u = navigator.userAgent + navigator.ap ...
- QT国际化示例, 检测系统语言,设置适合语言,按键切换显示语言
1.效果如下图,开启就自动检测系统语言,选择系统语言显示, UI有控件设置,在中文和英文之间切换.. 2. 源码 dialog.h #ifndef DIALOG_H #define DIALOG_H ...