题目大意:

不同的人在不同的队伍里,插入链表的时候假设这个链表里有他的队友,就把它放到最后一个队友的最后。假设没有队友,就把它放到整个链表的最后面。

出链表的时候把第一个人拿出来。

思路分析:

要模拟这个链表就要记录这整个链表中的队伍存在的情况。

所以要再开一个链表的头指针和尾指针,在整个大的链表中再模拟小区域的链表。

然后就是deque部分,也就是注意head的推断以及更新。

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <algorithm>
  4. #include <cstring>
  5. #include <queue>
  6. #include <map>
  7. #define maxn 222222
  8. using namespace std;
  9.  
  10. struct node
  11. {
  12. int data,next,front;
  13. }list[maxn];
  14. int head[1111];
  15. int tail[1111];
  16. int vis[1111111];
  17. int quenext[1111111];
  18. int listhead;
  19. int listtail;
  20.  
  21. void print()
  22. {
  23. int x=listhead;
  24. while(x)
  25. {
  26. printf("%d->",list[x].data);
  27. x=list[x].next;
  28. }
  29. puts("");
  30. }
  31. int main()
  32. {
  33. int n;
  34. int CASE=1;
  35. while(scanf("%d",&n)!=EOF && n)
  36. {
  37. memset(vis,0,sizeof vis);
  38. for(int i=1;i<=n;i++)
  39. {
  40. int t;
  41. scanf("%d",&t);
  42. for(int j=0;j<t;j++)
  43. {
  44. int a;
  45. scanf("%d",&a);
  46. vis[a]=i;
  47. }
  48. }
  49.  
  50. int num=0;
  51. listhead=1;
  52. listtail=1;
  53.  
  54. memset(head,0,sizeof head);
  55. memset(quenext,0,sizeof quenext);
  56. memset(tail,0,sizeof tail);
  57.  
  58. char str[11];
  59. printf("Scenario #%d\n",CASE++);
  60.  
  61. while(scanf("%s",str)!=EOF && str[0]!='S')
  62. {
  63. if(str[0]=='E')
  64. {
  65. int a;
  66. scanf("%d",&a);
  67. int belong=vis[a];
  68.  
  69. //printf("---%d\n",head[belong]);
  70.  
  71. if(!head[belong])
  72. {
  73. list[listtail].next=++num;
  74. listtail=num;
  75. list[listtail].next=0;
  76. list[num].data=a;
  77. head[belong]=tail[belong]=num;
  78. // print();
  79. continue;
  80. }
  81.  
  82. list[++num].next=list[tail[belong]].next;
  83. list[num].data=a;
  84. list[tail[belong]].next=num;
  85.  
  86. if(tail[belong]==listtail)listtail=num;
  87.  
  88. quenext[tail[belong]]=num;
  89. tail[belong]=num;
  90. }
  91. else
  92. {
  93. int cur=listhead;
  94. listhead=list[listhead].next;
  95. int belong=vis[list[cur].data];
  96. printf("%d\n",list[cur].data);
  97. head[belong]=quenext[cur];
  98. }
  99. // print();
  100. }
  101. puts("");
  102. }
  103. return 0;
  104. }

hdu 1387 Team Queue (链表)的更多相关文章

  1. HDU 1387 Team Queue( 单向链表 )

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. HDU 1387 Team Queue

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. Team Queue(STL练习题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others ...

  4. hdu 1387(Team Queue) STL

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  5. Team Queue (HDU:1387)

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  6. Team Queue (uva540 队列模拟)

    Team Queue Queues and Priority Queues are data structures which are known to most computer scientist ...

  7. ACM题目————Team Queue

    Queues and Priority Queues are data structures which are known to most computer scientists. The Team ...

  8. Team Queue

    Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 2471   Accepted: 926 Descrip ...

  9. Team Queue(多队列技巧处理)

    Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

随机推荐

  1. nginx区分手机与电脑浏览器并进入相应站点

    本文要讲的的是如何使用nginx区分pc和手机访问不同的网站,是物理上完全隔离的两套网站(一套移动端.一套pc端),这样带来的好处pc端和移动端 的内容可以不一样,移动版网站不需要包含特别多的内容,只 ...

  2. 基于visual Studio2013解决C语言竞赛题之0509杨辉三角

     题目

  3. 应用程序无法正常启动0xc000007b

    参考: http://jingyan.baidu.com/article/ff42efa9181bbbc19e22022f.html DirectX修复工具: http://blog.csdn.net ...

  4. cocos2d-实现读取.plist文件(使用数组CCArray)

    学习札记之cocos2d-x2.1.1实现读取.plist文件(使用数组CCArray) <?xml version="1.0" encoding="UTF-8&q ...

  5. Java 找出四位数的全部吸血鬼数字 基础代码实例

    /**  * 找出四位数的全部吸血鬼数字  * 吸血鬼数字是指位数为偶数的数字,能够由一对数字相乘而得到,而这对数字各包括乘积的一半位数的数字,当中从最初的数字中选取的数字能够随意排序.  * 以两个 ...

  6. 演练5-3:Contoso大学校园管理系统3

    在前面的教程中,我们使用了一个简单的数据模型,包括三个数据实体.在这个教程汇中,我们将添加更多的实体和关系,按照特定的格式和验证规则等自定义数据模型. Contoso大学校园管理系统的数据模型如下. ...

  7. haproxy 配置日志

    jrhppt01:/root# vim /etc/haproxy/haproxy.cfg # this config needs haproxy-1.1.28 or haproxy-1.2.1 glo ...

  8. 基于visual Studio2013解决C语言竞赛题之0804成绩筛选

     题目

  9. C++里面的取整函数

    #include<math.h> double ceil(double x) //向上取整 double floor(double x) //向下取整 也能够用数据类型强制转换,那要看数据 ...

  10. easyUI相关知识

    $("#sportGroupInfoDialog").dialog("open");//打开一个对话框,设置这个对话框的的布局方式 $('#sportGroup ...