当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5929:Basic Data Structure

题目描述
Mr. Frog learned a basic data structure recently, which is called stack.There are some basic operations of stack:

$\bullet $ PUSH x: put x on the top of the stack, x must be 0 or 1.
$\bullet $ POP: throw the element which is on the top of the stack.

Since it is too simple for Mr. Frog, a famous mathematician who can prove "Five points coexist with a circle" easily, he comes up with some exciting operations:

$\bullet $REVERSE: Just reverse the stack, the bottom element becomes the top element of the stack, and the element just above the bottom element becomes the element just below the top elements... and so on.
$\bullet $QUERY: Print the value which is obtained with such way: Take the element from top to bottom, then do NAND operation one by one from left to right, i.e. If  $a_{top},a_{top-1},\cdots , a_1$ is corresponding to the element of the Stack from top to the bottom, $value = a_{top}$ nand $a_{top-1}$ nand ... nand $a_1$. Note that the Stack will not change after QUERY operation. Specially, if the Stack is empty now,you need to print ”Invalid.”(without quotes).

By the way, NAND is a basic binary operation:

$\bullet $ 0 nand 0 = 1
$\bullet $ 0 nand 1 = 1
$\bullet $ 1 nand 0 = 1
$\bullet $ 1 nand 1 = 0

Because Mr. Frog needs to do some tiny contributions now, you should help him finish this data structure: print the answer to each QUERY, or tell him that is invalid.
输入解释
The first line contains only one integer T ($T \leq 20$), which indicates the number of test cases.

For each test case, the first line contains only one integers N ($2 \leq N \leq 200000$), indicating the number of operations.

In the following N lines, the i-th line contains one of these operations below:

$\bullet $ PUSH x (x must be 0 or 1)
$\bullet $ POP
$\bullet $ REVERSE
$\bullet $ QUERY

It is guaranteed that the current stack will not be empty while doing POP operation.
输出解释
For each test case, first output one line "Case #x:w, where x is the case number (starting from 1). Then several lines follow,  i-th line contains an integer indicating the answer to the i-th QUERY operation. Specially, if the i-th QUERY is invalid, just print "Invalid."(without quotes). (Please see the sample for more details.)
输入样例
2
8
PUSH 1
QUERY
PUSH 0
REVERSE
QUERY
POP
POP
QUERY
3
PUSH 0
REVERSE
QUERY
输出样例
Case #1:
1
1
Invalid.
Case #2:
0
提示
In the first sample: during the first query, the stack contains only one element 1, so the answer is 1. then in the second query, the stack contains 0, l
(from bottom to top), so the answer to the second is also 1. In the third query, there is no element in the stack, so you should output Invalid. 
来自杭电HDUOJ的附加信息
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5929

最后修改于 2020-10-25T23:26:49+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
7000/3500MS(Java/Others) 65536/65536K(Java/Others)