博客园  :: 首页  :: 联系 :: 管理

随笔分类 -  Algorithm

Data structure, Algorithm, Concrete Mathematics, Combinatorics
摘要:转自http://blog.csdn.net/zxzxy1988/article/details/8587244给定两个已经排序好的数组(可能为空),找到两者所有元素中第k大的元素。另外一种更加具体的形式是,找到所有元素的中位数。本篇文章我们只讨论更加一般性的问题:如何找到两个数组中第k大的元素?不过,测试是用的两个数组的中位数的题目,Leetcode第4题Median of Two Sorted Arrays方案1:假设两个数组总共有n个元素,那么显然我们有用O(n)时间和O(n)空间的方法:用merge sort的思路排序,排序好的数组取出下标为k-1的元素就是我们需要的答案。这个方法比较 阅读全文

posted @ 2013-09-09 21:17 Apprentice89 阅读(994) 评论(0) 推荐(0)

摘要:(Shoemaker's Problem)A shoemaker hasNorders from customers which he must satisfy. The shoemaker can work on only one job in each day, and jobs usually take several days. For theith job, the integerTi(1Ti1, 000) denotes the number of days it takes the shoemaker to finish the job.But popularity ha 阅读全文

posted @ 2012-12-23 19:49 Apprentice89 阅读(271) 评论(0) 推荐(0)

摘要:Stacks of Flapjacks原文链接 http://blog.csdn.net/yzfuture2010/article/details/8091337有一堆煎饼,直径各异,摞成一堆。可用一把铲子插入任意两张饼之间,完成一次对铲子之上所有饼的翻转操作。假设最底部的饼的位置为1,最顶层的饼的位置为n。对第i (1≤i≤n) 张饼及其上的所有饼的一次翻转操作可以记为flip(i)。最左边一列经过flip(3)变为中间一列,而中间一列经过flip(1)变为最右边一列。求算法,使得能对任意给出的一堆饼经过如上操作变为有序堆。堆中最小直径的饼在最顶层,最大直径的饼在最底层。算法很简单,在n个. 阅读全文

posted @ 2012-12-23 11:53 Apprentice89 阅读(905) 评论(0) 推荐(0)