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 ...
随机推荐
- uboot相关的几篇好文
http://www.eeworld.com.cn/mcu/2015/0727/article_21246.html http://blog.csdn.net/kernel_yx/article/de ...
- 【Head First Servlets and JSP】笔记19:JavaBeans与JSP动作元素(<jsp:setProperty.....>、<jsp:getProperty.....>)
内容来自imooc. 1.什么是JSP动作元素 2.在JSP页面中如何使用Javabeans <jsp:......>表示这是一个JSP动作元素 3.使用JSP动作元素创建JavaBean ...
- 数独C语言算法
备好:http://blog.chinaunix.net/uid-26456800-id-3380612.html
- Python面向对象编程高级特性
***这里还是根据网上资料,主要是廖雪峰老师的教程学习的笔记,主要介绍python面向对象的高级特性,笔记不全,只是记录自己觉得容易出错的地方*** 1.python作为一种动态语言,他的动态绑定机制 ...
- python进阶02
1.import导入模块 import sys sys.path:显示的是:从显示目录中查找要导入的模块文件. 程序执行时导入模块路径:sys.path.append('/home/itcast/xx ...
- java深入探究12-框架之Structs
注意每次修改配置文件后必须项目重启 Structs2=structs1+xwork Struct2框架预先实现了一些功能: 1.请求数据的封装:2.文件上传的功能3.对国际化功能的简化4.文件效验功能 ...
- php 当前时间计算操作
首先要设置时间为中国时区 date_default_timezone_set('PRC'); 对于获取当前时间戳后的各种时间计算 数据库保存最好用时间戳 当前时间time() 上一天 echo dat ...
- BZOJ 4066 kd-tree 矩形询问求和
第一次遇见强制在线的题目 每个操作都和前面的ans有关 所以不能直接离线做 在这个问题中 kdtree更像一个线段树在一维单点修改区间询问的拓展一样 如果区间被询问区间完全包含 就不用继续递归 插入时 ...
- vue 列表渲染 v-for循环
v-for循环指令类似与html中C标签的循环,同样可以遍历数组,集合. 1.这里演示一下遍历数组的基本用法,代码如下 <!DOCTYPE html> <html> <h ...
- jsp中的<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+ ...