[TOC] 勤于总结,持续输出! 1.栈 1.1栈的定义 栈(stack)是限定在 表尾进行插入和删除 的操作的 线性表 。 我们把允许插入和删除的一端称为栈顶(top),另一端称为栈底(bottom),不包含任何数据元素的栈称为空栈。栈又称为 后进先出 (Last In First Out)的线性 ...
分类:
其他好文 时间:
2018-04-16 22:48:07
阅读次数:
216
使用栈来实现队列的如下操作: push(x) -- 将一个元素放入队列的尾部。pop() -- 从队列首部移除元素。peek() -- 返回队列首部的元素。empty() -- 返回队列是否为空。注意: 你只能使用标准的栈操作-- 也就是只有push to top, peek/pop from to ...
分类:
其他好文 时间:
2018-04-09 13:05:39
阅读次数:
149
collections的常用类型有: 计数器(Counter) 双向队列(deque) 默认字典(defaultdict) 有序字典(OrderedDict) 可命名元组(namedtuple) 使用以上类型时需要导入模块 from collections import * 1. Counter C ...
分类:
其他好文 时间:
2018-04-08 18:28:46
阅读次数:
212
实例:制作猜字游戏,添加历史记录功能,显示用户最近猜过的数字 解决方案:使用容量为n的队列存储历史记录 deque(序列, n):生成一个容量为n的序列,当序列中存储第n+1个数据时,则从左/右将溢出一个数; pickle.dump(python对象, 文件名, 文件权限):创建一个文件,并将一个p ...
分类:
其他好文 时间:
2018-04-06 20:21:18
阅读次数:
140
例: from collections import deque q = deque([], 3) q.append(1) q.append(2) q.append(3) print(q) 输出:deque([1, 2, 3]) q.append(4) print(q) 输出:deque([2, 3 ...
分类:
编程语言 时间:
2018-04-06 17:34:39
阅读次数:
209
描述 使用STL中的deque,完成入队、出队、获取队首、获取队尾等基本操作。 部分代码已经给出,请补充完整,提交时请勿包含已经给出的代码。 int main() { deque<int> qu; int n; cin>>n; while(n--) { Op(qu); } deque<int>::i ...
分类:
其他好文 时间:
2018-04-05 14:29:56
阅读次数:
143
第一遍看的时候立即想到了哈希表。 再想时觉得两个队列,一个用来排队伍之间的顺序,一个用来排队伍内部成员的顺序即足够了。 DEQUE的时候先判断哪只队伍排在队首,之后再让该队伍中的首队员出列。 整体没有什么难度,注意的一些小tips如下: 1、多个测试用例一定注意先初始化(因为这个wa了两次。。呃呃) ...
分类:
其他好文 时间:
2018-04-04 23:42:03
阅读次数:
312
【题目描述】 Given an array of n integer with duplicate number, and a moving window(size k), move the window at each iteration from the start of the array, ...
You are given an array of N integers. You should support the following queries on this array. 0 L R : Find the minimum integer in the range AL, AL+1, ...
分类:
其他好文 时间:
2018-03-27 01:57:47
阅读次数:
163
一、类与成员变量 LinkedList继承自AbstractSequentialList抽象类,实现了List<E>、 Deque、Cloneable、Serializable接口。 其中: Deque是Queue的子接口是双向队列,它支持从两个端点方向检索和插入元素。 实现Cloneable接口的 ...
分类:
其他好文 时间:
2018-03-26 16:54:55
阅读次数:
164