hdu 1387 Team Queue (链表)
题目大意:
不同的人在不同的队伍里,插入链表的时候假设这个链表里有他的队友,就把它放到最后一个队友的最后。假设没有队友,就把它放到整个链表的最后面。
出链表的时候把第一个人拿出来。
思路分析:
要模拟这个链表就要记录这整个链表中的队伍存在的情况。
所以要再开一个链表的头指针和尾指针,在整个大的链表中再模拟小区域的链表。
然后就是deque部分,也就是注意head的推断以及更新。
- #include <cstdio>
- #include <iostream>
- #include <algorithm>
- #include <cstring>
- #include <queue>
- #include <map>
- #define maxn 222222
- using namespace std;
- struct node
- {
- int data,next,front;
- }list[maxn];
- int head[1111];
- int tail[1111];
- int vis[1111111];
- int quenext[1111111];
- int listhead;
- int listtail;
- void print()
- {
- int x=listhead;
- while(x)
- {
- printf("%d->",list[x].data);
- x=list[x].next;
- }
- puts("");
- }
- int main()
- {
- int n;
- int CASE=1;
- while(scanf("%d",&n)!=EOF && n)
- {
- memset(vis,0,sizeof vis);
- for(int i=1;i<=n;i++)
- {
- int t;
- scanf("%d",&t);
- for(int j=0;j<t;j++)
- {
- int a;
- scanf("%d",&a);
- vis[a]=i;
- }
- }
- int num=0;
- listhead=1;
- listtail=1;
- memset(head,0,sizeof head);
- memset(quenext,0,sizeof quenext);
- memset(tail,0,sizeof tail);
- char str[11];
- printf("Scenario #%d\n",CASE++);
- while(scanf("%s",str)!=EOF && str[0]!='S')
- {
- if(str[0]=='E')
- {
- int a;
- scanf("%d",&a);
- int belong=vis[a];
- //printf("---%d\n",head[belong]);
- if(!head[belong])
- {
- list[listtail].next=++num;
- listtail=num;
- list[listtail].next=0;
- list[num].data=a;
- head[belong]=tail[belong]=num;
- // print();
- continue;
- }
- list[++num].next=list[tail[belong]].next;
- list[num].data=a;
- list[tail[belong]].next=num;
- if(tail[belong]==listtail)listtail=num;
- quenext[tail[belong]]=num;
- tail[belong]=num;
- }
- else
- {
- int cur=listhead;
- listhead=list[listhead].next;
- int belong=vis[list[cur].data];
- printf("%d\n",list[cur].data);
- head[belong]=quenext[cur];
- }
- // print();
- }
- puts("");
- }
- return 0;
- }
hdu 1387 Team Queue (链表)的更多相关文章
- HDU 1387 Team Queue( 单向链表 )
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1387 Team Queue
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue(STL练习题)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...
- hdu 1387(Team Queue) STL
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Team Queue (HDU:1387)
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- Team Queue (uva540 队列模拟)
Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...
- ACM题目————Team Queue
Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...
- Team Queue
Team Queue Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 2471 Accepted: 926 Descrip ...
- Team Queue(多队列技巧处理)
Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
随机推荐
- nginx区分手机与电脑浏览器并进入相应站点
本文要讲的的是如何使用nginx区分pc和手机访问不同的网站,是物理上完全隔离的两套网站(一套移动端.一套pc端),这样带来的好处pc端和移动端 的内容可以不一样,移动版网站不需要包含特别多的内容,只 ...
- 基于visual Studio2013解决C语言竞赛题之0509杨辉三角
题目
- 应用程序无法正常启动0xc000007b
参考: http://jingyan.baidu.com/article/ff42efa9181bbbc19e22022f.html DirectX修复工具: http://blog.csdn.net ...
- cocos2d-实现读取.plist文件(使用数组CCArray)
学习札记之cocos2d-x2.1.1实现读取.plist文件(使用数组CCArray) <?xml version="1.0" encoding="UTF-8&q ...
- Java 找出四位数的全部吸血鬼数字 基础代码实例
/** * 找出四位数的全部吸血鬼数字 * 吸血鬼数字是指位数为偶数的数字,能够由一对数字相乘而得到,而这对数字各包括乘积的一半位数的数字,当中从最初的数字中选取的数字能够随意排序. * 以两个 ...
- 演练5-3:Contoso大学校园管理系统3
在前面的教程中,我们使用了一个简单的数据模型,包括三个数据实体.在这个教程汇中,我们将添加更多的实体和关系,按照特定的格式和验证规则等自定义数据模型. Contoso大学校园管理系统的数据模型如下. ...
- haproxy 配置日志
jrhppt01:/root# vim /etc/haproxy/haproxy.cfg # this config needs haproxy-1.1.28 or haproxy-1.2.1 glo ...
- 基于visual Studio2013解决C语言竞赛题之0804成绩筛选
题目
- C++里面的取整函数
#include<math.h> double ceil(double x) //向上取整 double floor(double x) //向下取整 也能够用数据类型强制转换,那要看数据 ...
- easyUI相关知识
$("#sportGroupInfoDialog").dialog("open");//打开一个对话框,设置这个对话框的的布局方式 $('#sportGroup ...