Maximum Element In A Stack

时间限制: 10 Sec  内存限制: 128 MB

题目描述

As an ACM-ICPC newbie,Aishah is learning data structures in computer science. She has already known that a stack,

as a data structure,can serve as a collection of elements with two operations:

• push,which inserts an element to the collection, and

• pop, which deletes the most recently inserted element that has not yet deleted.

Now, Aishah hopes a more intelligent stack which can display the maximum element in the stack dynamically.

Please write a program to help her accomplish this goal and go through a test with several operations.

Aishah assumes that the stack is empty at first.

Your program will output the maximum element in the stack after each operation.

If at some point the stack is empty, the output should be zero.

输入

The input contains several test cases and the first line is a positive integer T

indicating the number of test cases which is up to 50.

To avoid unconcerned time consuming in reading data,each test case is described by seven integers n (1 ≤ n ≤ 5 × 10^6 ) ,p, q, m (1 ≤ p , q , m ≤ 10^9 ), SA, SB and SC (10^4 ≤ SA , SB , SC ≤ 10^6 ). The integer n is the number of operations,and your program should generate all operations using the following code in C++.

int n,p,q,m;
unsigned int SA,SB,SC;
unsigned int rng61(){SA ^= SA << 16;SA ^= SA >> 5;SA ^= SA << 1;unsigned int t = SA;SA = SB;SB = SC;SC ^= t ^ SA;return SC;}void gen(){scanf("%d%d%d%d%u%u%u" &n,&p,&q,&m,&SA,&SB,&SC);for(int i = 1; i <= n; i++){if(rng61() % (p + q) < p)PUSH(rng61() % m + 1);elsePOP();}
}

The procedure PUSH(v) used in the code inserts a new element with value v into the stack

and the procedure POP() pops the topmost element in the stack or does nothing if the stack is empty.

输出

For each test case,output a line containing Case #x: y where x is the test case number starting from 1,

and y is equal to  where ai is the answer after the i-th operation and ⊕ means bitwise xor.

样例输入

2
4 1 1 4 23333 66666 233333
4 2 1 4 23333 66666 233333

样例输出

Case #1: 19
Case #2: 1

提示

The first test case in the sample input has 4 operations: 
    • POP();  
    • POP();  
    • PUSH(1);  
    • PUSH(4).  
The second test case also has 4 operations:  
    • PUSH(2);  
    • POP();  
    • PUSH(1);  
    • POP().

题意:

实现一个特殊的栈,

Maximum Element In A Stack 数据结构相关推荐

  1. 【2018icpc宁夏邀请赛现场赛】【Gym - 102222A】Maximum Element In A Stack(动态的栈中查找最大元素)

    https://nanti.jisuanke.com/t/41285 题干: As an ACM-ICPC newbie, Aishah is learning data structures in ...

  2. Codeforces 889C Maximum Element(DP + 计数)

    题目链接  Maximum Element 题意  现在有这一段求序列中最大值的程度片段: (假定序列是一个1-n的排列) int fast_max(int n, int a[]) { int ans ...

  3. LeetCode——1846. 减小和重新排列数组后的最大元素(Maximum Element After Decreasing and Rearranging)[中等]——分析及代码(Java)

    LeetCode--1846. 减小和重新排列数组后的最大元素[Maximum Element After Decreasing and Rearranging][中等]--分析及代码[Java] 一 ...

  4. 01-复杂度2 Maximum Subsequence Sum (25分)(数据结构)(C语言实现)

    Given a sequence of K integers { N​1 , N2​​ , -, N​K ​​ }. A continuous subsequence is defined to be ...

  5. CF886E Maximum Element(dp、组合数学)

    Solution\text{Solution}Solution 纯纯的dp题. 关键在于我们 dp 时只关注不同元素之间的相对大小. 非法情况不易统计,考虑转而考虑合法情况再用全排列减. 设计 fif ...

  6. python算法和数据结构_Python中的数据结构和算法

    python算法和数据结构 To 至 Leonardo da Vinci 达芬奇(Leonardo da Vinci) 介绍 (Introduction) The purpose of this ar ...

  7. 5专题总结-数据结构

    专题5-数据结构 2017-07-13 C++ Primer P329好好研读,stack,queue,priority_queue都是顺序容器适配器adaptor.(接受一种已有的容器类型,使其行为 ...

  8. 【DS】About Stack

    栈 一言以蔽之,就是后进的先出(LIFO). C语言实现代码: #include<stdio.h> #include<stdlib.h>typedef struct Stack ...

  9. 【霍洛维兹数据结构】栈和队列 | 动态循环队列 | 迷宫问题 | 表达式 | 多重栈多重队列

    前言: 最近在读霍罗维兹的<数据结构基础>(Fundamentals of Data Structures in C),本篇博客为阅读笔记和知识总结. 目录 Ⅰ. 栈(STACKS) 0x ...

最新文章

  1. distributed processing(分布式处理)
  2. QT的QSvgGenerator类的使用
  3. CF-1249 F.Maximum Weight Subset(贪心)
  4. [Linux基础环境/软件]Linux下安装resin web服务器(涉及gcc、jdk环境部署)
  5. linux net 伪指令码,1.2.2. ldr pWTCON
  6. 如何在C ++中使用String compare()?
  7. 一篇文章读懂UI设计师与美工区别(附视频教程+学习线路图)
  8. 五、实现一个10秒钟的倒计时,即:从10~0依次打印,每次打印间隔一秒
  9. 使用Python的pandas库操作Excel
  10. 计算机基础中英文打字,中英文打字
  11. IAR9.30以上版本安装、注册、新建工程和配置过程详细介绍
  12. 【转帖】刘备三顾茅庐,请Elasticsearch出山
  13. android n自带游戏,Android N玩游戏更快了 但国产ROM要等很久
  14. RGB与16进制值互相转换
  15. costmap_2d 中计算footprint 的内切圆半径和外切圆半径的函数解析——点到线段的距离计算
  16. FreeRTOS 链表的深度讲解
  17. 【模板】数据结构之STL常用容器
  18. 夕阳西下,小卤蛋和妲己姐姐竟然手牵手讨论Spring...
  19. Android关机闹钟实现
  20. saltstack学习视频—老男孩—超详细—网盘下载

热门文章

  1. linux 光盘yum源搭建
  2. 【剑指offer】21、调整数组顺序使奇数在偶数前面
  3. Discuz常见小问题-_如何修改网站LOGO
  4. Python连接SQL Server数据库 - pymssql使用基础
  5. 快速排序算法javascript实现
  6. HDU1010 Tempter of the Bone dfs(奇偶减枝)
  7. 计算机基础7试题,大学计算机应用基础试题
  8. url充定向 html转义,html、javascript、url特殊字符的转义诠释及使用方法详解
  9. linux下写sql语言,如何写这个sql语句?
  10. js调用php函数兵每秒刷新,深入理解JavaScript立即调用函数表达式(IIFE)