algorithm learning
文章平均质量分 53
WHJObject
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
算法导论第三版快速排序(三数取中划分)Median-of-3 partition
7-5中文版 page 105英文版 page 188a.对x=A'[i]必然有1,...,i-1, i, i+1,...,np[i] = (i-1)*(n-i)/(C(n,3))所以i=1和n时pi=0b.平凡实现:1/n三数取中:p[(n+1)/2]直接做差吧,我没有划成比较具有美感的式子不过两个值都是趋于0,差也是0,n->infinity原创 2016-01-24 16:35:09 · 2743 阅读 · 0 评论 -
算法导论14.1-8
原题现在有一个圆上的n条弦,没条弦都由其端点定义。请给出一个能在O(n*log(n))时间内确定圆内相交弦的算法。此题想了蛮久,知道两条弦的端点如果顺序交叉分布,那么就能推出相交但是圆上点的排序,或者说怎么拿弦建树不知道,难以下手思想来源于以下链接http://bbs.youkuaiyun.com/topics/280085502有人把文字以更加容易理解的方式表述了一下(是否更转载 2016-02-06 16:23:46 · 645 阅读 · 0 评论 -
算法导论15
原题:设计一个O(n^2)时间的算法,求一个n个数的序列的最长单调递增子序列想法:记录每个位置元素一定被包含在其中的子序列的最大长度靠后的元素加入的子序列依赖之前的子序列两个for循环,O(n^2)显然#includeusing namespace std;struct lAndMax{ int length, max;};int main(){ in原创 2016-02-08 20:16:20 · 390 阅读 · 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 lengthsl1; l2; ···; ln,原创 2016-02-09 22:56:42 · 3314 阅读 · 1 评论 -
算法导论15-6公司聚会计划Planning a company party
Professor Stewart is consulting for the president of a corporation that is planninga company party. The company has a hierarchical structure; that is, the supervisorrelation forms a tree rooted at原创 2016-02-10 21:33:22 · 3652 阅读 · 0 评论 -
算法导论22.2-8
题目:Thediameter of a tree T D .V; E/ is defined as , that is, thelargest of all shortest-path distances in the tree. Give an efficient algorithm tocompute the diameter of a tree, and an原创 2016-02-19 16:17:58 · 733 阅读 · 0 评论 -
算法导论22.3-13
题目:判断一个图是否为单联通图对图做DFS,对每个点记录 in 和 out ,in为遍历到的时间点,out为离开该点极其所有后续的时间点如果一个点出现了第二次 in,也就是第二次被遍历到(在这种情况下应当停止向下遍历,但依然加上一个in[2]),如果in[2]>out[1],则必然是有第二条简单路径到达该点。原创 2016-02-22 21:19:22 · 2188 阅读 · 0 评论
分享