UVA 540 TLE 求助,谢谢~~
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&category=103&problem=481&mosmsg=Submission+received+with+ID+12489532
这道题我用了三种方法都是超时。。。不知道是哪里错了,求各位大神提点下,或者给出一个错误的例子,谢谢大家了。。。
#include<algorithm>
#include<iostream>
#include<iterator>
#include<cstring>
#include<string>
#include<map>
#include<list>
using namespace std;
map<int,int> arry;
list<int> team;
int tag[1050];
int main()
{
int t=0,n;
while(cin>>n&&n)
{
memset(tag,0,sizeof(tag));
arry.clear();
team.clear();
int i,j,k,m,s;
for(i=0;i<n;i++)
{
cin>>m;
for(j=0;j<m;j++)
{
cin>>s;
arry.insert(make_pair(s,i));
}
}
cout<<"Scenario #"<<++t<<endl;
string str;
int p,q;
map<int,int>::iterator pos;
while(cin>>str&&str!="STOP")
{
if(str=="ENQUEUE")
{
cin>>k;
pos=arry.find(k);
p=pos->second;
if(tag[p]==0)
{
team.push_back(k);
tag[p]++;
}
else
{
pos=arry.find(team.back());
q=pos->second;
list<int>::iterator iter=team.end();
iter--;
while(1)
{
if(p==q) break;
iter--;
pos=arry.find(*iter);
q=pos->second;
}
iter++;
team.insert(iter,k);
tag[p]++;
}
}
else if(str=="DEQUEUE")
{
pos=arry.find(team.front());
int d=pos->second;
tag[d]--;
cout<<team.front()<<endl;
team.pop_front();
}
}
}
return 0;
}