uva - 540 Team Queue Solution

uva - 540 Team Queue Solution

uva id: erfan05
Accepted Time: 0.070


#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<map>
#include<algorithm>
#include<queue>
#include<string>


using namespace std;
int arr[1000000], task_value[1000];

int main(){

map<int, queue<int>> mymap;
map<int, queue<int>>::iterator mit;
map<int, int> task_value_map;
int  n, x, i, team, max_value, y, kase=1;
string str;
while (cin >> team){
if (team == 0)
break;
cout << "Scenario #" << kase++ << endl;
for (i = 1; i <= team; i++){
cin >> n;
while (n--){
cin >> x;
arr[x] = i;
}
}
max_value = 1;
fill(task_value, task_value + team + 1, 0);
mymap.clear();
while (cin >> str){
if (str[0] == 'E'){
cin >> x;
y = arr[x];
if (task_value[y] == 0){
task_value[y] = max_value;
queue<int> q;
q.push(x);
mymap[max_value] = q;
task_value_map[max_value] = y;
max_value++;
}
else{
mymap[task_value[y]].push(x);
}
}
else if (str[0] == 'D'){
mit = mymap.begin();
cout << mit->second.front() << endl;
mit->second.pop();
if (mit->second.empty()){
task_value[task_value_map[mit->first]] = 0;
mymap.erase(mit);
}
}
else{
break;
}
}
cout << endl;
}
return 0;
}

Comments

Popular posts from this blog

uva 679 - Dropping Balls Solution

uva 481 - What Goes Up Solution

uva-10077 Solution --- The Stern-Brocot Number System