日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Maximum Element In A Stack 数据结构

發(fā)布時間:2024/10/6 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Maximum Element In A Stack 数据结构 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

?Maximum Element In A Stack

時間限制:?10 Sec??內(nèi)存限制:?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().??

題意:

實現(xiàn)一個特殊的棧,

?

總結(jié)

以上是生活随笔為你收集整理的Maximum Element In A Stack 数据结构的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。