![](https://img-blog.csdnimg.cn/20201014180756913.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
algorithm learning
文章平均质量分 53
WHJObject
这个作者很懒,什么都没留下…
展开
-
算法导论第三版快速排序(三数取中划分)Median-of-3 partition
7-5 中文版 page 105 英文版 page 188 a. 对x=A'[i] 必然有1,...,i-1, i, i+1,...,n p[i] = (i-1)*(n-i)/(C(n,3)) 所以i=1和n时pi=0 b. 平凡实现:1/n 三数取中:p[(n+1)/2] 直接做差吧,我没有划成比较具有美感的式子 不过两个值都是趋于0,差也是0,n->infinity原创 2016-01-24 16:35:09 · 2571 阅读 · 0 评论 -
算法导论14.1-8
原题 现在有一个圆上的n条弦,没条弦都由其端点定义。 请给出一个能在O(n*log(n))时间内确定圆内相交弦的算法。 此题想了蛮久,知道两条弦的端点如果顺序交叉分布,那么就能推出相交 但是圆上点的排序,或者说怎么拿弦建树不知道,难以下手 思想来源于以下链接 http://bbs.csdn.net/topics/280085502 有人把文字以更加容易理解的方式表述了一下(是否更转载 2016-02-06 16:23:46 · 586 阅读 · 0 评论 -
算法导论15
原题: 设计一个O(n^2)时间的算法,求一个n个数的序列的最长单调递增子序列 想法: 记录每个位置元素一定被包含在其中的子序列的最大长度 靠后的元素加入的子序列依赖之前的子序列 两个for循环,O(n^2)显然 #include using namespace std; struct lAndMax { int length, max; }; int main() { in原创 2016-02-08 20:16:20 · 335 阅读 · 0 评论 -
算法导论第三版15-4整齐打印Printing neatly
Consider the problem of neatly printing a paragraph with a monospaced font (all characters having the same width) on a printer. The input text is a sequence of n words of lengths l1; l2; ···; ln,原创 2016-02-09 22:56:42 · 3129 阅读 · 1 评论 -
算法导论15-6公司聚会计划Planning a company party
Professor Stewart is consulting for the president of a corporation that is planning a company party. The company has a hierarchical structure; that is, the supervisor relation forms a tree rooted at原创 2016-02-10 21:33:22 · 3506 阅读 · 0 评论 -
算法导论22.2-8
题目: The diameter of a tree T D .V; E/ is defined as , that is, the largest of all shortest-path distances in the tree. Give an efficient algorithm to compute the diameter of a tree, and an原创 2016-02-19 16:17:58 · 668 阅读 · 0 评论 -
算法导论22.3-13
题目:判断一个图是否为单联通图 对图做DFS,对每个点记录 in 和 out ,in为遍历到的时间点,out为离开该点极其所有后续的时间点 如果一个点出现了第二次 in,也就是第二次被遍历到(在这种情况下应当停止向下遍历,但依然加上一个in[2]),如果in[2]>out[1],则必然是有第二条简单路径到达该点。原创 2016-02-22 21:19:22 · 2050 阅读 · 0 评论