uva 12207 - That is Your Queue

 

 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).没看到这一条件,不仔细;

转载于:https://www.cnblogs.com/aze-003/p/5157000.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值