最短路径的O(ElgV)的解法。
使用邻接表存储图,使用堆操作选取下一个最小路径点。
本题的难度并不在最短路径本身这个算法,而是在于堆的操作:
1 使用双重指针操作堆的节点,可以省去直接复制操作堆节点,提高效率,并且这才是有效操作动态地址数据的方法,不用双重指针,我思考了下,觉得更加不好做。
2 使用一个数组记录当前顶点在堆中的位置,相当于一个hash表了,可以需要的时候,直接从表中查找表...
分类:
其他好文 时间:
2014-06-07 02:03:17
阅读次数:
214
题目:给定两个串s1和s2,对s1串,我们可以将其分割成两部分,这两部分都不为空,而被分割成的两部分,又可以递归的进行分割,直到不能进行分割为止,也就是只有一个字符的时候,就不在分割了。问s2是否由s1的这种分割表示中,某步分割成的两部分交换得到的。这种交换可以在不同的分割点进行多次。
/* s1
|__________p____________| ...
分类:
其他好文 时间:
2014-06-05 11:09:06
阅读次数:
207
Problem Description:
Say you have an array for which the ith element is the price of a given stock on day i.
Design an algorithm to find the maximum profit. You may complete at most two transa...
分类:
其他好文 时间:
2014-06-05 09:33:52
阅读次数:
342
如果尿布臭了,就换掉它。
1.Duplicated Code 重复代码
Extract MethodPull Up MethodForm Template Method --》 Template Method 模式Substitute Algorithm --》 函数算法替代
2.Long Method 过长的函数
“间接层”所带来的全部利益--解释能力、共享能...
分类:
其他好文 时间:
2014-06-05 08:45:40
阅读次数:
291
【题目】
Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row is greater than the last integer of the previous ...
分类:
其他好文 时间:
2014-06-05 08:28:43
阅读次数:
321
VIBE是Barnich和Droogenbroeck在2011年发表的《VIBE:A
universalbackground subtraction algorithm for video
sequence》中提出。其在模型中大量的使用了随机策略,有着意想不到的准确率和鲁棒性,该方法简单实用,计算代...
分类:
其他好文 时间:
2014-05-31 01:25:54
阅读次数:
1657
Say you have an array for which theithelement
is the price of a given stock on dayi.Design an algorithm to find the maximum
profit. You may complete a...
分类:
其他好文 时间:
2014-05-30 16:19:05
阅读次数:
320
Given an array of integers, every element
appearstwiceexcept for one. Find that single one.Note:Your algorithm should have
a linear runtime complexity...
分类:
其他好文 时间:
2014-05-30 16:16:29
阅读次数:
190
Given an array of integers, every element
appearsthreetimes except for one. Find that single one.Note:Your algorithm
should have a linear runtime comp...
分类:
其他好文 时间:
2014-05-30 15:15:53
阅读次数:
225
Say you have an array for which theithelement
is the price of a given stock on dayi.Design an algorithm to find the maximum
profit. You may complete a...
分类:
其他好文 时间:
2014-05-30 15:00:54
阅读次数:
335