标签:field ams term time mat span careful blog hdu
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2051 Accepted Submission(s): 713
1 //608MS 4544K 1051B G++ 2 #include<iostream> 3 #include<algorithm> 4 #include<string.h> 5 #include<queue> 6 #include<map> 7 #include<vector> 8 using namespace std; 9 const int N = 1005; 10 typedef queue<int> INTQ; 11 12 int main() 13 { 14 int n,m,a; 15 char op[10]; 16 int cas=1; 17 while(cin>>n && n){ 18 map<int ,int>TERM; 19 for(int i=1;i<=n;i++){ 20 cin>>m; 21 for(int j=0;j<m;j++){ 22 cin>>a; 23 TERM[a]=i; 24 } 25 } 26 27 INTQ V[N]; 28 map<int, int>M2V; 29 int index=1; 30 int head_index=index; 31 cout<<"Scenario #"<<cas++<<endl; 32 while(cin>>op){ 33 if(strcmp(op, "STOP")==0){ 34 break; 35 } 36 else if(strcmp(op, "ENQUEUE")==0){ 37 cin>>a; 38 if(M2V[TERM[a]]==0){ 39 INTQ tQ; 40 tQ.push(a); 41 V[index] = tQ; 42 M2V[TERM[a]] = index; 43 index = (index+1)%N; 44 }else{ 45 V[M2V[TERM[a]]].push(a); 46 } 47 48 }else{ 49 int a=V[head_index].front(); 50 V[head_index].pop(); 51 cout<<a<<endl; 52 if(V[head_index].empty()){ 53 M2V[TERM[a]] = 0; 54 head_index = (head_index+1)%N; 55 } 56 } 57 58 } 59 cout<<endl; 60 } 61 return 0; 62 }
标签:field ams term time mat span careful blog hdu
原文地址:http://www.cnblogs.com/GO-NO-1/p/6229790.html