UVA 540 (Team Queue UVA-540)

Source: Internet
Author: User

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)

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.