[POJ2259]Team Queue (队列,模拟)

2559是栈,2259是队列,真的是巧啊

题意

模拟队列

思路

水题

代码

因为太水,不想打,发博客只是为了与2559照应,于是附上lyd的std

#include <queue>
#include <cstdio>
#include <iostream>
using namespace std;
const int N = 1000000, T = 1006;
int t, f[N], id = 0;
char s[10];
queue<int> q[T];

void Team_Queue() {
    q[0] = queue<int>();
    for (int i = 1; i <= t; i++) {
        int n;
        scanf("%d", &n);
        while (n--) {
            int x;
            scanf("%d", &x);
            f[x] = i;
        }
        q[i] = queue<int>();
    }
    cout << "Scenario #" << ++id << endl;
    while (scanf("%s", s) && s[0] != ‘S‘) {
        if (s[0] == ‘E‘) {
            int x;
            scanf("%d", &x);
            if (q[f[x]].empty()) q[0].push(f[x]);
            q[f[x]].push(x);
        } else {
            int x = q[0].front();
            printf("%d\n", q[x].front());
            q[x].pop();
            if (q[x].empty()) q[0].pop();
        }
    }
    cout << endl;
}

int main() {
    while (cin >> t && t) Team_Queue();
    return 0;
}

原文地址:https://www.cnblogs.com/lincold/p/10162432.html

时间: 2024-10-12 16:11:40

[POJ2259]Team Queue (队列,模拟)的相关文章

poj-2259 team queue(数据结构)

第一遍看的时候立即想到了哈希表. 再想时觉得两个队列,一个用来排队伍之间的顺序,一个用来排队伍内部成员的顺序即足够了. DEQUE的时候先判断哪只队伍排在队首,之后再让该队伍中的首队员出列. 整体没有什么难度,注意的一些小tips如下: 1.多个测试用例一定注意先初始化(因为这个wa了两次..呃呃) 2.判断是否需要进行队伍排序可以另立一个flag数组用来标记某支队伍是否已经在队列中,若不在则插入该队伍序号. 3.别忘了按要求输出(最后空一行,否则就PE了) ac代码如下: #include<i

UVa 540 (团体队列) Team Queue

题意: 每个人都属于一个团体,在排队的时候,如果他所在的团体有人在队伍中,则他会站到这个团体的最后.否则站到整个队伍的队尾. 输出每次出队的人的编号. 分析: 容易看出,长队中,在同一个团体的人是排在一起的. 所以用两个队列模拟即可,一个队列保留团体的编号,另外一个队列数组存放的是团体中每个人的编号. 1 #include <cstdio> 2 #include <queue> 3 #include <map> 4 using namespace std; 5 6 co

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(

UVA - 540 Team Queue(STL,队列 )

Team Queue Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu Submit Status Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known,

Team Queue POJ - 2259 (队列)

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 queue in front of the Mensa is a team queue, for exa

POJ 2259 Team Queue 数据结构 队列

Team Queue Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3282   Accepted: 1188 Description Queues and Priority Queues are data structures which are known to most computer scientists. The Team Queue, however, is not so well known, thoug

ACM学习历程——UVA540 Team Queue(队列,map:Hash)

Description Team Queue   Team Queue  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 queue in front

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

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