POJ 2259 队列

编程入门 行业动态 更新时间:2024-10-25 12:20:15

POJ 2259 <a href=https://www.elefans.com/category/jswz/34/1771257.html style=队列"/>

POJ 2259 队列

题意

传送门 POJ 2259 Team Queue

题解

用 1 1 1 个队列维护已在队中的小组索引,用 t t t 个队列维护各个小组在队中的元素,就能够 O ( 1 ) O(1) O(1) 时间处理各个操作。

#include <algorithm>
#include <cstdio>
#include <queue>
using namespace std;
const int maxn = 1000005, maxt = 1005;
int id[maxn];
queue<int> used, team[maxt];int main()
{int t, c = 0;while (~scanf("%d", &t) && t){printf("Scenario #%d\n", ++c);while (used.size())used.pop();for (int i = 0; i < t; ++i){while (team[i].size())team[i].pop();int n, x;scanf("%d", &n);for (int j = 0; j < n; ++j){scanf("%d", &x);id[x] = i;}}char op[10];while (~scanf(" %s", op) && op[0] != 'S'){int x, k;switch (op[0]){case 'E':scanf("%d", &x);k = id[x];if (team[k].empty())used.push(k);team[k].push(x);continue;case 'D':k = used.front();printf("%d\n", team[k].front());team[k].pop();if (team[k].empty())used.pop();}}puts("");}return 0;
}

更多推荐

POJ 2259 队列

本文发布于:2024-02-25 21:41:31,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1700375.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:队列   POJ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!