1 #include <cstdio> 2 #include <iostream> 3 #include <deque> 4 using namespace std; 5 6 int main() 7 { 8 deque<long> cir; 9 long P, C, cas = 0; 10 11 while(scanf("%ld%ld", &P, &C) && P) 12 { 13 cir.clear(); 14 for (int i = 1; i <= P && i <= 1000; i++) // 1 ≤ C ≤ 1000 15 cir.push_back(i); 16 17 printf("Case %ld:\n", ++cas); 18 19 while(C--) 20 { 21 char c; 22 getchar(); 23 scanf("%c", &c); 24 25 if(c == ‘N‘) 26 { 27 long tempN = cir.front(); 28 cir.pop_front(); 29 cir.push_back(tempN); 30 cout << tempN << endl; 31 }else if(c == ‘E‘) 32 { 33 long x; 34 scanf("%ld", &x); 35 for(deque<long>::iterator it = cir.begin(); it != cir.end(); ++ it) 36 if(*it == x) 37 { 38 cir.erase(it); 39 break; 40 } 41 cir.push_front(x); 42 } 43 } 44 } 45 return 0; 46 }
Time limit exceeded的原因:and C, the number of commands to process (1 ≤ C ≤ 1000).没看到这一条件,不仔细;
时间: 2024-10-26 12:46:47