uva 12207 - That is Your Queue

时间:2022-01-12 15:54:58
 #include <cstdio>
#include <iostream>
#include <deque>
using namespace std; int main()
{
deque<long> cir;
long P, C, cas = ; while(scanf("%ld%ld", &P, &C) && P)
{
cir.clear();
for (int i = ; i <= P && i <= ; i++) // 1 ≤ C ≤ 1000
cir.push_back(i); printf("Case %ld:\n", ++cas); while(C--)
{
char c;
getchar();
scanf("%c", &c); if(c == 'N')
{
long tempN = cir.front();
cir.pop_front();
cir.push_back(tempN);
cout << tempN << endl;
}else if(c == 'E')
{
long x;
scanf("%ld", &x);
for(deque<long>::iterator it = cir.begin(); it != cir.end(); ++ it)
if(*it == x)
{
cir.erase(it);
break;
}
cir.push_front(x);
}
}
}
return ;
}

Time limit exceeded的原因:and C, the number of commands to process (1 ≤ C ≤ 1000).没看到这一条件,不仔细;