| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
WHY TLE? HELP ME PLZ!#include<iostream>
#include<map>
#include<queue>
#include<string>
#define maxn 1010
using namespace std;
map<int,int> R;
queue<int> Qt,Qp[maxn];
int main()
{
int ss = 0;
while (1)
{
int n;
cin>>n;
if (n == 0) break;
for (int i = 1; i<=n; i++)
{
int m;
cin>>m;
for (int j = 0; j<m; j++)
{
int x;
cin>>x;
R[x] = i;
}
}
cout<<"Scenario #"<<++ss<<endl;
while (1)
{
int flag = 0;
string st;
cin>>st;
switch (st[0])
{
case 'S':
flag = 1;
break;
case 'E':
int x;
cin>>x;
if (!Qp[R[x]].empty()) Qp[R[x]].push(x);
else
{
Qt.push(R[x]);
Qp[R[x]].push(x);
}
break;
case 'D':
cout<<Qp[Qt.front()].front()<<endl;
Qp[Qt.front()].pop();
if (Qp[Qt.front()].empty())
Qt.pop();
break;
}
if (flag) break;
}
while (!Qt.empty())
Qt.pop();
for (int i = 0; i<maxn;i++)
{
queue<int> tmp;
swap(Qp[i],tmp);
}
cout<<endl;
}
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator