• 问题描述
  • Just these days, we've learned about "Queue". It's a kind of data structure.
    Elaine is cranky. She made her own Queue.
    That Queue only has two operations:

    • Top x : Make the element x to the top of the Queue.
    • Next: Output the top element and pop it and then push it to the back of the Queue.

    SORRY, because of the bug of Judge Core. The code "remove" will be judged as "DANGEROUS_CODE". We will fix it next time.

  • 输入
  • The first line is an integer T, indicates the number of cases.
    Then follow T cases.
    The first line of each case has two integer n and m (n, m <= 1000), indicate the number of elements and operations.
    Then follow m lines of operations. Each line is an operation.
  • 输出
  • For each "Next" operation, output the answer.
    看到这题的时候,我的第一反应就是用双端队列来解决,于是就去详细看了下双端队列的内容,发现它真的很强大,居然可以访问下标!
    #include<cstdio>
    #include<deque>
    #include<iterator>
    using namespace std;int main()
    {int T,n,m,i,j,temp;char str[10];while(~scanf("%d",&T)){while(T--){deque<int>qu;deque<int>::iterator it;scanf("%d%d%*c",&n,&m);for(i=1;i<=n;i++)qu.push_back(i);//注意不是push_front() while(m--){scanf("%s",str);if(str[0]=='T'){scanf("%d%*c",&temp);for(i=0;i<qu.size();i++)if(qu[i]==temp)  //双端队列可访问下标 {qu.erase(qu.begin()+i);break;}qu.push_front(temp);}else{int t=qu.front();qu.pop_front();printf("%d\n",t);}}}}return 0;
    }

NOJ [1184] Elaine's Queue相关推荐

  1. Java多线程系列--【JUC线程池 02】- 线程池原理(一)

    参考:http://www.cnblogs.com/skywang12345/p/java_threads_category.html 概要 在前面一章"Java多线程系列--"J ...

  2. NOJ电子老鼠闯迷宫

    NOJ电子老鼠闯迷宫 描述: 有一只电子老鼠被困在如下图所示的迷宫中.这是一个12*12单元的正方形迷宫,黑色部分表示建筑物,白色部分是路.电子老鼠可以在路上向上.下.左.右行走,每一步走一个格子.现 ...

  3. Python 标准库之 Queue

    1. Queue 概念 队列 Queue 多应用在多线程应用中,多线程访问共享变量.对于多线程而言,访问共享变量时,队列 Queue 是线程安全的. Python Queue 模块有三种队列及构造函数 ...

  4. Python多线程(3)——Queue模块

    Python多线程(3)--Queue模块 Queue模块支持先进先出(FIFO)队列,支持多线程的访问,包括一个主要的类型(Queue)和两个异常类(exception classes). Pyth ...

  5. ActiveMQ—Queue与Topic区别

    Queue与Topic区别 转自:http://blog.csdn.net/qq_21033663/article/details/52458305 队列(Queue)和主题(Topic)是JMS支持 ...

  6. LeetCode刷题记录12——232. Implement Queue using Stacks(easy)

    LeetCode刷题记录12--232. Implement Queue using Stacks(easy) 目录 LeetCode刷题记录12--232. Implement Queue usin ...

  7. C++ Stack Queue priority_queue

    栈stack:stack 后入先出(LIFO) q.top() 获取栈顶元素(并不删除) q.pop() 删除栈顶元素 q.push(x) 向栈中加入元素 q.empty() 判断栈是否为空 队列qu ...

  8. C++ STL: 超详细 容器 deque 以及 适配器queue 和 stack 源码分析

    文章目录 前言 deque 实现 deque类 _Deque_iterator 类 deque 的元素插入 insert函数 deque如何模拟空间连续 queue 实现 stack 的实现 前言 C ...

  9. tp5.0 queue 队列操作

    检查是否安装redis(没有请自行百度安装): phpinfo: 配置thinkphp-queue,没有请执行 composer require topthink/think-queue 加入: 创建 ...

  10. C++ STL:stack和queue

    http://blog.csdn.net/wallwind/article/details/6858634 http://blog.csdn.net/chao_xun/article/details/ ...

最新文章

  1. CF 8D Two Friends (三分+二分)
  2. Improved Alpha-Tested Magnification for Vector Textures and Special Effects
  3. 用Jmeter做微信小程序项目接口测试【案例】
  4. Python学习之路:内置函数
  5. p4.pm p4python p4perl p4api 的使用方法
  6. Hybris Administration console功能一览
  7. windows中端口号被占用的解决方法
  8. 厨房手工工具行业调研报告 - 市场现状分析与发展前景预测(2021-2027年)
  9. Forrester《2021年应用安全现状报告》提要
  10. 有这些信号,你可能需要跳槽了
  11. 工业机器人四大家族(ABB、库卡、安川)全套资料,欢迎下载!
  12. Qt编写1024游戏
  13. 期货突破(期货突破交易法)
  14. ubuntu18.04安装opencv记录
  15. 一个selenium python网页脚本(机器人),针对随聊520(www.suiliao520.com)匿名聊天匹配陌生人的网站
  16. 知乎:电脑长时间不关机会缩短电脑寿命吗?
  17. Unity中的矩阵Matrix
  18. 神经网络 深度神经网络,深度神经网络知识图谱
  19. 内嵌式js微信扫码登录及自定义样式
  20. 记得十年前谷歌大量使用python_关于利用Python玩转百万答题

热门文章

  1. 图卷积神经网络与标签传播的区别
  2. python数据分析多元 线性回归
  3. 大量数据表的优化方案
  4. 专科学计算机编程,学编程怎么才能学的又快又好?
  5. [jruby] warbler 配置问题说明
  6. 石开kk高中计算机考试,石开KK电脑考试软件
  7. git提交代码的时候未获取最新代码
  8. linux下动态域名的实践
  9. 关闭Typora拼写检查功能
  10. c#设置导出Excel的列宽