ZOJ - 4016 Mergeable Stack 【LIST】】的更多相关文章

题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 题意 模拟栈的三种操作 第一种 push 将指定元素压入指定栈 第二种 pop pop出指定栈的栈顶元素 如果栈空 输出 EMPTY 第三种 Move a b 将 b 中的所有元素 移动到 栈a中 思路 本来想到用 双端队列 因为 在移动的时候 比较方便 但是MLE了 后来想到用链表 但是在 比赛的时候 没有想到 有 STL 中 有LIST 这个容器 手写…
[传送门]http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 [题目大意]初始有n个空栈,现在有如下三种操作: (1) 1 s v  即 s.push(v) (2) 2 s 即 s.pop() 输出弹出的元素,如果栈s为空则输出 "EMPTY" (3) 3 s t 把t栈元素全部移到s栈中,使s的尾部与t的首部相连. 现在有若干上述三种类型的操作,遇到操作2则输出相应内容. [题解]由于站的数量n和操作次数…
Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given initially empty stacks, there are three types of operations: 1 s v: Push the value onto the top of the -th stack. 2 s: Pop the topmost value out of the -th stack, and print that…
Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, there are three types of operations: 1 s v: Push the value  onto the top of the -th stack. 2 s: Pop the topmost value out of the -th stack, and print tha…
Mergeable Stack Time Limit: 2 Seconds      Memory Limit: 65536 KB Given  initially empty stacks, there are three types of operations: 1 s v: Push the value  onto the top of the -th stack. 2 s: Pop the topmost value out of the -th stack, and print tha…
模拟题,用链表来进行模拟 # include <stdio.h> # include <stdlib.h> typedef struct node { int num; struct node *q; struct node *h; }node; struct Node { node *start; node *end; int sum; }m[]; int main() { int k; scanf("%d", &k); while (k--) { i…
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4016 直接用栈爆内存,看网上大神用数组实现的,构思巧妙,学习了! AC代码: /* * 用数组实现栈的一些操作 */ #include <cstdio> #include <cstring> using namespace std; const int maxn = 300005; int arr[maxn]; //存放所有的数据 //top代表栈…
Implement a stack with min() function, which will return the smallest number in the stack. It should support push, pop and min operation all in O(1) cost. Notice min operation will never be called if there is no number in the stack.   Example push(1)…
Implement a stack. You can use any data structure inside a stack except stack itself to implement it. Have you met this question in a real interview?     Example push(1) pop() push(2) top() // return 2 pop() isEmpty() // return true push(3) isEmpty()…
题目链接 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3959 AC代码 #include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <iostream> #include <algorithm> #include <cmath> #inc…