Hoj 1456 Team Queue
团队队列。
方法一:直接用链表模拟,用STL list直接模拟。
[cpp]
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
using namespace std;
int team[1000005];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int t;
int cas = 0;
char cmd[20];
list<int> q;
list<int> final;
list<int>::iterator last[1005];
while(scanf(" %d",&t)!=EOF && t!=0)
{
q.clear();
final.clear();
cas++;
int num,t1;
for(int i=1; i<=t; i++)
{
scanf(" %d",&num);
for(int j=0; j<num; j++)
{
scanf(" %d",&t1);
team[t1] = i;
}
}
for(int i=1; i<=t; i++) last[i] = q.end();
printf("Scenario #%d\n",cas);
while(scanf(" %s",cmd)!=EOF && strcmp(cmd,"STOP")!=0)
{
if(strcmp(cmd,"ENQUEUE") == 0)
{
int w;
scanf("%d",&w);
if(last[team[w]]==q.end())
last[team[w]]=final.insert(final.end(),w);
else
{
last[team[w]]++;
last[team[w]]=final.insert(last[team[w]],w);
}
}
else if(strcmp(cmd,"DEQUEUE") == 0)
{
int temp = final.front();
printf("%d\n",temp);
list<int>::iterator ti = final.begin();
if(ti == last[team[temp]])
last[team[temp]] = q.end();
final.pop_front();
}
}
printf("\n");
}
return 0;
}
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <queue>
#include <list>
#include <algorithm>
using namespace std;
int team[1000005];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
int t;
int cas = 0;
char cmd[20];
list<int> q;
list<int> final;
list<int>::iterator last[1005];
while(scanf(" %d",&t)!=EOF && t!=0)
{
q.clear();
final.clear();
cas++;
int num,t1;
for(int i=1; i<=t; i++)
{
scanf(" %d",&num);
for(int j=0; j<num; j++)
{
scanf(" %d",&t1);
team[t1] = i;
}
}
for(int i=1; i<=t; i++) last[i] = q.end();
printf("Scenario #%d\n",cas);
while(scanf(" %s",cmd)!=EOF && strcmp(cmd,"STOP")!=0)
{
if(strcmp(cmd,"ENQUEUE") == 0)
{
 
补充:软件开发 , C++ ,