uva 540

来源:互联网 发布:界面设计软件 编辑:程序博客网 时间:2024/06/05 04:10

题目大意:

有个所谓的team排序, 给出t个队伍,以及这些队伍的成员。 然后进行排队。 

ENQUEUE x: 把x插入队列中时。如果队列没有该元素的队员,则插入队列的最后面。如果队列中已经有了他的队员,那么插入最后一个队员之后。 

DEQUEUE:  把队头的元素删除,并且输出

STOP:  停止

#include <iostream>#include <cstdio>#include <cstring>#include <list>#include <iterator>using namespace std;const int MAXN = 1000000;int t ;int ele[MAXN];   //记录元素(element)所在的team.list<int >lst;list<int >::iterator team[1001];//指向每个team在lst中排最后一个的元素的位置。若lst中没有team中的元素,则指向lst.end().int main(){int ca = 0 ;while (cin >> t && t){lst.clear();int num,tmp;for (int i = 1 ; i <= t ; i++){team[i] = lst.end();cin>>num;for (int j = 0 ; j < num ; j++){cin>>tmp;ele[tmp] = i ;}}cout << "Scenario #" << ++ca << endl;string s;while (cin >> s && s != "STOP"){if ( s == "ENQUEUE"){cin>>tmp;if (team[ele[tmp]] != lst.end()){team[ele[tmp]]++;team[ele[tmp]] = lst.insert(team[ele[tmp]], tmp);}else team[ele[tmp]] = lst.insert(team[ele[tmp]], tmp);}else if (s == "DEQUEUE"){int top = lst.front(); // 第一个元素的引用if (team[ele[top]] == lst.begin()) //第一个元素的迭代器team[ele[top]] = lst.end();   //如果队首元素所属的队列只有一个元素只有回归初始化lst.pop_front();cout<<top<<endl;}}cout<<endl;}return 0;}


原创粉丝点击