(队列的应用5.3.2)POJ 2259 Team Queue(队列数组的使用)
/* * POJ_2259.cpp * * Created on: 2013年10月30日 * Author: Administrator */#include <iostream>#include <cstdio>#include <queue>#include <cstring>#include <map>using namespace std;const int maxn = 1010;int main(){int n;bool visited[maxn];int counter = 1;while(scanf("%d",&n)!=EOF,n){int i;/** * que: 总队列,里面存的是子队列的编号 * q[i]: 第i个子队列,里面存的是元素值 */queue<int> q[maxn],que;map<int,int> team;for(i = 0 ; i < n ; ++i){int m;scanf("%d",&m);int t;while(m--){scanf("%d",&t);team[t] = i;}}memset(visited,false,sizeof(visited));printf("Scenario #%d\n",counter++);char str[25];while(scanf("%s",str)!=EOF){if(strcmp(str,"STOP") == 0){printf("\n");break;}if(strcmp(str,"ENQUEUE") == 0){int t;scanf("%d",&t);q[team[t]].push(t);if(visited[team[t]] == false){que.push(team[t]);visited[team[t]] = true;}}else if(strcmp(str,"DEQUEUE") == 0){printf("%d\n",q[que.front()].front());q[que.front()].pop();if(q[que.front()].empty()){visited[que.front()] = false;que.pop();}}}}return 0;}