03 2018 档案

摘要:一 综述 线段树是一种类似与二叉搜索树的结构,及非叶子节点一定包含了左右子树。每个节点存储了一个区间(线段)的值(可以是最值,区间和等)。所以对于这个节点,需要的信息应该包括 该节点表示的连续区间l,以及该节点的数据。 我们可以用线段树来做什么呢?线段树可以在log(n)的时间内实现区间修改(单点修 阅读全文
posted @ 2018-03-31 19:52 blueattack 阅读(206) 评论(0) 推荐(0)
摘要:一.倍增算法的前期铺垫 我们记节点v到根的深度为depth(v)。那么如果节点w是节点u和节点v的最近公共祖先的话,让u往上走(depth(u)-depth(w))步,让v往上走(depth(v)-depth(w))步,都将走到节点w。因此,我们首先让u和v中较深的一个往上走|depth(u)-de 阅读全文
posted @ 2018-03-30 21:32 blueattack 阅读(246) 评论(0) 推荐(0)
摘要:给你一个图,求让图连通的边权和最小值 krustra算法是基于加边法,将所有边权排序,每次加一条边,将两个点放在同一个集合中。如果新加的点不在同一个集合中,就合并(并查集) 涉及到排序,可以用结构体存节点的信息,之后按边权从小到大排序。随后遍历n条边,判断两个节点是否在一个集合中,不在则加入 这个问 阅读全文
posted @ 2018-03-30 20:37 blueattack 阅读(694) 评论(0) 推荐(1)
摘要:有一个经典问题: 长度为n的序列,插入若干数字后,让其形成回文串。求插入的数字最少的个数p p=n-最长公共子序列 最长公共子序列可以利用动态规划的思想,具体可以用下面这个图来表示: 将序列打印出来 阅读全文
posted @ 2018-03-17 17:40 blueattack 阅读(1682) 评论(0) 推荐(0)
摘要:最长上升子序列是对于一个给定的序列求出最长的一个序列(不需要连续),该序列是上升的。这个问题可以有O(n^2)和O(nlogn)两种解法 O(n^2)采取动态规划的思想,f[i]表示以第i个元素结尾的序列最长上升的子序列长度 O(nlogn) 阅读全文
posted @ 2018-03-17 17:23 blueattack 阅读(313) 评论(0) 推荐(0)
摘要:In the big cities, the subway systems always look so complex to the visitors. To give you some sense, the following figure shows the map of Beijing su 阅读全文
posted @ 2018-03-17 13:33 blueattack 阅读(198) 评论(0) 推荐(0)
摘要:堆排序是一种选择排序,其最好,最坏,平均时间复杂度均为O(nlogn),是一种不稳定的排序。 首先我们来认识一下堆的结构。 对于大顶堆,其根节点的值要大于左右孩子,小顶堆则相反。那么我们可以利用满二叉树的性质,用数组来存储堆结构。i是根节点,则左右孩子为2*i和2*i+1 堆排序的算法顺序如下: 1 阅读全文
posted @ 2018-03-17 10:16 blueattack 阅读(137) 评论(0) 推荐(0)
摘要:An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any 阅读全文
posted @ 2018-03-14 10:29 blueattack 阅读(170) 评论(0) 推荐(0)
摘要:There is a kind of balanced binary search tree named red-black tree in the data structure. It has the following 5 properties: (1) Every node is either 阅读全文
posted @ 2018-03-13 20:26 blueattack 阅读(369) 评论(0) 推荐(0)
摘要:map可以实现key到value的一一映射,如果是一对多的,我们可以使用multimap multimap<int,int>mp; mp.insert(make_pair(first,second)); map默认是按照key值从小到大进行排序的,如果希望按照从大到小进行排序,可以使用 map<in 阅读全文
posted @ 2018-03-13 19:08 blueattack 阅读(6084) 评论(0) 推荐(0)
摘要:A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open 阅读全文
posted @ 2018-03-10 21:08 blueattack 阅读(260) 评论(0) 推荐(0)
摘要:A graph which is connected and acyclic can be considered a tree. The height of the tree depends on the selected root. Now you are supposed to find the 阅读全文
posted @ 2018-03-09 19:21 blueattack 阅读(162) 评论(0) 推荐(0)
摘要:已知后序与中序输出前序(先序):后序:3, 4, 2, 6, 5, 1(左右根)中序:3, 2, 4, 1, 6, 5(左根右) 已知一棵二叉树,输出前,中,后时我们采用递归的方式。同样也应该利用递归的思想: 对于后序来说,最后一个节点肯定为根。在中序中可以找到左子树的个数,那么就可以在后序中找到左 阅读全文
posted @ 2018-03-09 17:27 blueattack 阅读(452) 评论(0) 推荐(0)
摘要:There is a public bike service in Hangzhou City which provides great convenience to the tourists from all over the world. One may rent a bike at any s 阅读全文
posted @ 2018-03-07 21:22 blueattack 阅读(654) 评论(0) 推荐(0)