is a more complex simulation problem. There are two kinds of queues, one is the Corps column, the former is backward. The others are small queues for each group, because if the team members have teammates, they will get priority in the group queue. So let's set up two queues and a map, and setting up a map does not have to worry about how many arrays to open. Then open two queues, one is the basic Q1, the other is q2[1010] general STL container such as String vector deque are two methods of direct initialization (not rigorous) one is a (MAXN) this and a one-dimensional array, directly assigned to how many elements, The other is A[MAXN] This is almost an array of containers, each a[i] represents a container. You can also use a string similar to A[i][j] to find the elements in the container and then first put the small groups into the Corps column (if there is no other elements in the group queue), and then remove the first group in front of the queue to remove the top of the line, the first element of the output group queue, If the first group queue does not have an element after this, then kick off the group queue directly My Code (RUJIA algorithm)
#include <bits/stdc++.h>//This place has to be careful not to follow the habit of defining arrays to put STL containers outside of Main, now I do not know how to clear the same as Memset 0 STL container, for this also WA. Using namespace Std;main () {int n; int cas=0; while (Cin>>n&&n) {map<int,int> MP; for (int i=0;i<n;i++) {int t; cin>>t; while (t--) {int num; cin>>num; Mp[num]=i; }} queue<int> q1,q2[1010]; printf ("Scenario #%d\n", ++cas); String A; while (Cin>>a) {if (a[0]== ' S ') is break; if (a[0]== ' D ') {int t=q1.front (); Cout<<q2[t].front () <<endl; Q2[t].pop (); if (Q2[t].empty ()) Q1.pop (); } if (a[0]== ' E ') {int num; cin>>num; int T=mp[num]; if (Q2[t].empty ()) Q1.push (t); Q2[t].push (num); }} cout<< "\ n";}}
UVA 540 (Team Queue UVA-540)