您的位置:首页 > 产品设计 > UI/UE

UVA 540 Team Queue

2016-07-16 23:07 309 查看

UVA-540

题意:先告诉你有t个团队,每个团队中的每一个人有一个编号。然后空的广场上x来了,如果x所在团队已经在了,那么x排到他的团队队列的最后一个,否则他就作为他那个团队的第一个排在大队列的最后一个。DEQUEUE 时就把排在大队列第一个团队队列的第一个出队并输出来。当第一个队列空了就从第二个上找,以此类推。

解题思路:一开始以为是给的团队的人都在了,改了半天,后面才发现只是告诉我们谁谁谁属于哪个团队,一开始都是没人的。按照它所说的去模拟就形了。

/*************************************************************************
> File Name: UVA-540.cpp
> Author: Narsh
>
> Created Time: 2016年07月16日 星期六 15时09分24秒
************************************************************************/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
queue<int> team[1010];
queue<int> que;
int xt[1203000],t,n,a;
int main () {
int num=0;
while (scanf("%d",&n) && n) {
num++;
printf("Scenario #%d\n",num);
while (!que.empty()) que.pop();
memset(xt,0,sizeof(xt));
for (int i = 1; i <= n; i++){
scanf("%d",&t);
while (!team[i].empty()) team[i].pop();
for (int j = 1; j <= t; j++) {
scanf("%d",&a);
xt[a] = i;
}
}
int k;
string s;
cin>>s;
while (s[0] != 'S') {
if (s[0] == 'E') {
scanf("%d\n",&a);
k=xt[a];
if (team[k].empty()) que.push(k);
team[k].push(a);
}
if (s[0] == 'D') {
k=que.front();
printf("%d\n",team[k].front());
team[k].pop();
if (team[k].empty()) que.pop();
}
cin>>s;
}
printf("\n");
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: