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;
}
时间: 2024-10-24 21:32:29

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 Submission(s): 1294    Accepted Submission(s): 442 Problem Description Queues and Priority Queues are data structures which are known to most computer

HDU 1387 Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1889    Accepted Submission(s): 639 Problem Description Queues and Priority Queues are data structures which are known to most computer

HDU 1387 Team Queue(优先队列)

Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1524    Accepted Submission(s): 515 Problem Description Queues and Priority Queues are data structures which are known to most compute

Team Queue(STL练习题)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1387 Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 1518    Accepted Submission(s): 511 Problem Description Queues and Priority Queues

hdu 1387(Team Queue) STL

Team Queue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2051    Accepted Submission(s): 713 Problem Description Queues and Priority Queues are data structures which are known to most computer

HDU 1908 Double Queue&lt;Set&gt;

Problem Description The new founded Balkan Investment Group Bank (BIG-Bank) opened a new office in Bucharest, equipped with a modern computing environment provided by IBM Romania, and using modern information technologies. As usual, each client of th

Team Queue

Team Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 129 Accepted Submission(s): 63   Problem Description Queues and Priority Queues are data structures which are known to most computer scie

Winter-2-STL-G Team Queue 解题报告及测试数据

Time Limit:3000MS     Memory Limit:0KB Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, though it occurs often in everyday life. At lunch time the q

UVa 540 Team Queue(团队队列)

题意  模拟团队队列的入队和出队 STL应用  用一个队列维护团队编号  再用一个队列数组维护个体 #include <cstdio> #include <cstring> #include <queue> #include <map> using namespace std; const int N = 1000005; int team[N]; int main() { int cas = 0, n, t, a; char cmd[20]; while(