![](https://img-blog.csdnimg.cn/20201014180756923.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 65
ShowLovE
这个作者很懒,什么都没留下…
展开
-
算法设计与分析习题2的部分解答
2-2:第5个应该是对的,其余的不是死循环就是搜索结果不正确。2-3:每次记录middle的位置,再注意(x a[n-1])的情况即可。2-8:每次比较a[middle]与middle的值即可: while( left { middle = (left+right) / 2; if( middle == a[middle] ) return middle; els原创 2006-03-09 22:00:00 · 3325 阅读 · 0 评论 -
习题2-4、2-5、2-6
2-4:1. 如果m非常小, 即m/10 2.如果m也是高精度, 将n分成n/m个部分, 每个部分用分治乘法, 复杂度为O(m^(log3)), 则总的复杂度为n/m*m^(log3), 即O(n*mlog(3/2)).2-5:对于大整数乘以10n只要在数组后添n个0即可。设u = a*10^(2n/3)+b*10^(n/3)+c, v = e*10^(2n/3)+f*10^(原创 2006-03-15 12:21:00 · 1611 阅读 · 0 评论 -
2-28、2-32
2-28:给出一种很麻烦的算法:1、用O(n)复杂度找出中位数。2、一次扫描记录下每个数与中位数距离。( O(n) )3、从距离数组中找出前k个最小数。( O(n) )2-32:1、只要证得不带权中位数xk满足带权中位数的条件即可,很容易证。2、先排序(O(nlogn)),扫描对权求和,每到达一个数判断其左部权和与右部权和是否都小于等于1/2,是则此数为带权中位数,否则继续原创 2006-03-20 12:26:00 · 1515 阅读 · 0 评论 -
关于快速排序和插入排序最坏时间复杂度为O(nlogn)的算法
1.快速排序:根据T(n) = T(ðn) + O(n) (0 因此关键问题是怎样解决划分标准的问题, 因此产生下列线性时间找中位数的算法:将数组a有n个元素, 划分成5个一组, 则共有[n/5]个元素, 对于每组用一般的排序找中位数,需要25次, 则总共需要O(25*[n/5]) = O(n), 然后在这些中位数中递归找其中位数需要T(n/5)次,然后以找到的中位数x来作为划分标准则显然原创 2006-03-21 12:32:00 · 10852 阅读 · 1 评论 -
prime judge(HOJ1356)
Given a positive integer, your job is writing a program to determine whether it is a prime number or not. Input There are several tests. Each test consists of a positive integer n(no more than 2^3原创 2006-03-22 12:39:00 · 2050 阅读 · 0 评论 -
习题2-24
突然觉得C++挺有趣的,因此俺从今天开始改用C++了……#include #include #include #include #include #include using namespace std;const int N = 100;int partition(vector&, int, int);void qsort(vector&, int, int);int swa原创 2006-03-25 13:19:00 · 1709 阅读 · 1 评论 -
zju1453(二维凸包)
Surround the TreesTime limit: 1 Seconds Memory limit: 32768K Total Submit: 532 Accepted Submit: 199 There are a lot of trees in an area. A peasant wants to buy a rope to surround all these tre原创 2006-03-26 01:37:00 · 1748 阅读 · 0 评论 -
zju2107
问题如下:Quoit DesignTime limit: 5 Seconds Memory limit: 32768K Total Submit: 1751 Accepted Submit: 362 Have you ever played quoit in a playground? Quoit is a game in which flat rings are pitc原创 2006-03-25 18:46:00 · 1780 阅读 · 0 评论 -
习题3
3-1:设f[i]表示前i个数最长递增子序列的长度,则有: f[i] = max{f[j] + 1}(i a[j]) (a为输入数组) 3-2: 即找最优LIS,每次找下一个数的位置用二分查找即可。 3-4:1.设a[i][j]表示用前i个硬币找j元钱所用的最少硬币数,则 a[i][j] = min{a[i-1][j-k*a[i]]+k} (0 2.由于计算第i行的值只要用到i-1行原创 2006-04-06 18:26:00 · 1693 阅读 · 1 评论