Topic Portal
Test instructions: Give some team members first, and then start the queue. If the person in front of the same group of people, straight line queue in the same group of the last one, or only in the last side. There are now queued and out-of-team operations.
Analysis: The key is to group the queue by the number of groups, with another queue to save the group ordinal, when there is no one in the group to replace a group. That's a good question.
Harvesting: The flexible use of queues
Code:
/************************************************* author:running_time* Created TIME:2015/9/9 Wednesday 14:37:14* File Name:m.cpp ************************************************/#include <cstdio> #include <algorithm># Include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string > #include <vector> #include <queue> #include <deque> #include <stack> #include <list># Include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime>using namespace std; #define Lson L, Mid, RT << 1#define Rson mid + 1, R, RT << 1 | 1typedef long ll;const int N = 1e3 + 10;const int INF = 0x3f3f3f3f;const int MOD = 1e9 + 7;queue<int> id;queue& Lt;int> num[n];map<int, int> mp;bool inq[n];char op[11];int n;void init (void) {while (!id.empty ()) Id.pop (); for (int i=1, i<=n; ++i) {while (!num[i].empty ())) Num[i].pop (); } memset (Inq, False, sizeof (INQ)); Mp.clear ();} int main (void) {int cas = 0; while (scanf ("%d", &n) = = 1) {if (!n) break; Init (); if (CAS) puts (""); printf ("Scenario #%d\n", ++cas); int x; for (int i=1; i<=n; ++i) {int m; scanf ("%d", &m); for (int j=1; j<=m; ++j) {scanf ("%d", &x); MP[X] = i; }} scanf ("%s", &op); while (strcmp (OP, "STOP")) {if (strcmp (OP, "ENQUEUE") = = 0) {scanf ("%d", &x); if (!inq[mp[x]]) {Inq[mp[x]] = true; Id.push (Mp[x]); } num[mp[x]].push (x); } else {if (Id.empty ()) continue; int fir = Id.front (); printf ("%d\n", Num[fir].front ()); Num[fir].pop (); if (Num[fir].empty ()) {Inq[fir] = false; Id.pop (); }} scanf ("%s", &op); }} return 0;}
Queue POJ 2259 Team queue