Queue POJ 2259 Team queue

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.