Scala函数默认使用最后一个语句的运行结果作为返回值。例如def distance(a:Int,b:Int):Int={ a*a+b*b}以a*a+b*b的运行结果作为返回值。这种返回值的方式渊源于其他函数式语言Lisp/Haskell等(个人猜测)。在近期工作中,我写了如下的代码:def br....
分类:
其他好文 时间:
2014-08-07 13:01:20
阅读次数:
270
题目:Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2. (each operation is counted as 1 step.)You ha....
分类:
编程语言 时间:
2014-08-07 05:11:48
阅读次数:
258
private static final int MAX_INTERVAL_FOR_CLICK = 250;
private static final int MAX_DISTANCE_FOR_CLICK = 100;
private static final int MAX_DOUBLE_CLICK_INTERVAL = 500;
int mDownX = 0;
...
分类:
移动开发 时间:
2014-08-06 23:12:02
阅读次数:
484
编辑距离(Edit Distance),又称Levenshtein距离,是指两个字串之间,由一个转成另一个所需的最少编辑操作次数。许可的编辑操作包括将一个字符替换成另一个字符,插入一个字符,删除一个字符。例如将kitten一字转成sitting:sitten (k→s)sittin (e→i)sit...
分类:
其他好文 时间:
2014-08-06 22:11:12
阅读次数:
207
import javax.swing.JOptionPane;public class Distance { public static void main(String[] args){ String input = JOptionPane.showInputDialog(nu...
分类:
其他好文 时间:
2014-08-06 21:42:42
阅读次数:
267
Description
The branch of mathematics called number theory is about properties of numbers. One of the areas that has captured the interest of number theoreticians for thousands of years is the qu...
分类:
其他好文 时间:
2014-08-06 19:06:42
阅读次数:
319
Dijkstra://寻求加权图起始点到各个节点的最短路径for i distance[presentNode] + length(i, presentNode) //更新节点距离 distance[i] = distance[presentNode] + length(i, presentNod....
分类:
其他好文 时间:
2014-08-05 22:20:20
阅读次数:
234
Metric spaces is a large class of spaces on which the closeness of two points is depicted by a distance function, or called a metric. Metric spaces ar...
分类:
其他好文 时间:
2014-08-05 03:04:28
阅读次数:
220
Floyd算法
Dijkstra算法是用于解决单源最短路径问题的,Floyd算法则是解决点对之间最短路径问题的。Floyd算法的设计策略是动态规划,而Dijkstra采取的是贪心策略。当然,贪心算法就是动态规划的特例。
算法思想
点对之间的最短路径只会有两种情况:
两点之间有边相连,weight(Vi,Vj)即是最小的。
通过另一点:中介点,两点相连,使weight(Vi,Vk)+weight(Vk,Vj)最小。
Min_Distance(Vi,Vj)=min{weight(Vi,Vj)...
分类:
其他好文 时间:
2014-08-04 14:25:07
阅读次数:
275