1 #include <iostream> 2 #include <map> 3 #include <queue> 4 #include <cstdio> 5 using namespace std; 6 int main() 7 { 8 int t,kase=0; 9 while(scanf("%d",&t),t) 10 { 11 printf("Scenario #%d ",++kase); 12 13 //记录所有人的团队编号 14 map<int ,int > team; //team[x]表示编号为x的所在的团队号 15 for(int i=0;i<t;i++) 16 { 17 int n,x; 18 scanf("%d",&n); 19 while(n--) 20 { 21 scanf("%d",&x); team[x]=i; 22 } 23 } 24 25 //模拟 26 queue<int >q,q2[1000]; 27 for(;;) 28 { 29 int x; 30 char cmd[10]; 31 scanf("%s",cmd); 32 if(cmd[0]=='S') 33 break; 34 else 35 if(cmd[0]=='D') 36 { 37 int t=q.front(); 38 printf("%d ",q2[t].front()); 39 q2[t].pop(); 40 if(q2[t].empty()) 41 q.pop(); 42 } 43 else 44 { 45 if(cmd[0]=='E') 46 { 47 scanf("%d",&x); 48 int t=team[x]; 49 if(q2[t].empty()) 50 q.push(t); 51 q2[t].push(x); 52 } 53 } 54 } 55 printf(" "); 56 57 } 58 return 0; 59 }
queue 还提供了优先队列,STL提供了更为简单的定义方法,例如,越小的整数优先级越大的优先队列,可以写成priority_queue<int,vector<int>,greater<int> >pq;