- 博客(50)
- 收藏
- 关注
原创 Binary Search Tree 转化为 (Circular) doubly LinkedList
参考:http://leetcode.com/2010/11/convert-binary-search-tree-bst-to.html
2014-04-27 10:13:26
215
原创 动态规划资料整理
http://people.cs.clemson.edu/~bcdean/dp_practice/http://community.topcoder.com/tc?module=Static&d1=tutorials&d2=dynProghttp://hawstein.com/posts/dp-novice-to-advanced.htmlhttp://hawstein.com
2014-04-13 12:04:48
231
原创 高效生成质数表的算法--Sieve of Eratosthenes
Sieve of Eratosthenes算法的思想是,首先从第一个质数2,开始
2014-04-09 14:58:31
405
转载 全面解释java中StringBuilder、StringBuffer、String类之间的关系
String的值是不可变的,这就导致每次对String的操作都会生成新的String对象,不仅效率低下,而且大量浪费有限的内存空间,StringBuffer是可变类,和线程安全的字符串操作类,任何对它指向的字符串的操作都不会产生新的对象,StringBuffer和StringBuilder类功能基本相似1. String 类 String的值是不
2014-04-06 22:39:10
176
转载 Morris Traversal方法遍历二叉树(非递归,不用栈,O(1)空间)
本文主要解决一个问题,如何实现二叉树的前中后序遍历,有两个要求:1. O(1)空间复杂度,即只能使用常数空间;2. 二叉树的形状不能被破坏(中间过程允许改变其形状)。通常,实现二叉树的前序(preorder)、中序(inorder)、后序(postorder)遍历有两个常用的方法:一是递归(recursive),二是使用栈实现的迭代版本(stack+iterative)。这
2014-04-06 11:10:01
236
转载 Hanoi Tower问题及其变形
当然、这是一个经典的递归问题~ 想必来看这篇博文的同学对汉诺塔应该不会陌生了吧, 写这篇博还是有初衷的: 之前学数据结构的时候自己看书、也上网上查了很多资料,资料都比较散、而且描述的不是很清楚,对于当时刚刚接触算法的我,要完全理解还是有一定难度。今天刚好有时间就整理了下思路、重写分析了一下之前的疑惑的地方、没有透彻的地方便都豁然开朗了。所以迫不及待把我的想法记录下来,
2014-04-03 18:44:50
260
原创 数组与链表的归并排序实现
本文中采用的是自顶向下的归并排序算法。数组的归并排序private void merge(Comparable[] a, Comparable[] aux, int lo, int mid, int hi) { assert isSorted(a, lo, mid); assert isSorted(a, mid+1, hi); for (int k = lo; k <=
2014-04-02 15:16:58
233
转载 寻找链表环入口
在网上找到对于这个问题很好的解释,加上了一点自己的注释1.如何判断链表有环? 同时用两个指针p1、p2指向表头,每次循环p1指向后继,p2指向后继的后继(即p2的速度是p1的两倍);循环的结束条件是,p2后继为空(无环)或p1==p2(有环)。2.如何证明这两点一定会相遇呢? 如果是连续地移动,即像物体运动时位移和时间是连续的而不是这样离散的,当然会相遇;而二者都
2014-03-31 18:21:48
267
原创 Java中的参数传递
今天在刷CC150的时候,需要在一个函数里把传入的参数置为null,结果失败了。。题目描述如下:Implement an algorithm to delete a node in the middle of a singly linked list,given only access to that node. EXAMPLE Input: the node c from t
2014-03-31 10:20:03
171
转载 Java中的String concatenation操作
最近开始在刷CC150, 在书中看到在做字符串连接的时候,使用"+"的效率较低。不明白原因,因此查阅了一些资料,加上自己的一些总结:当使用“+”来进行字符串连接的时候,实际上进行了如下的操作:创建一个StringBuffer对象string1的内容被复制到StringBuffer对象中string2的内容也被附加到StringBuffer对象中(完成了字符串连接的操作)结果
2014-03-30 10:04:10
595
原创 Coursera 程序设计实习 课程笔记
程序设计实习是北大在Coursera平台上开的一门课程,主要内容是C++。一、函数指针1.概念:程序运行期间,每个函数都会占用一段连续的内存空间。而函数名就是该函数所占内存区域的起始地址(也称“入口地址”)。我们可以将函数的入口地址赋给一个指针变量,使该指针变量指向该函数。然后通过指针变量就可以调用这个函数。这种指向函数的指针变量称为“函数指针”。
2014-03-28 22:18:36
288
转载 sscanf函数用法
函数原型:int sscanf( const char * src, const char * format, ...);int scanf( const char * format, ...);这两个函数很相似,只是第一个函数以src作为输入,而第二个函数以标准输入STDIN读取输入;format 是格式控制字符串,它包含控制字符(如:%d,%i,%s等),空白字符
2014-03-27 20:07:23
172
原创 Java中的Iterable和Iterator
由于是Java初学者,对于这个概念不是特别明白。今天看了一篇博文对这个问题有了进一步的理解。博文地址:http://blog.dreasgrech.com/2010/03/javas-iterators-and-iterables.html前几天在写coursera的AlgorithmsI这门课程的作业的时候不太明白为什么有时候用Iterator有时候用Iterable,下面谈一下自己的体
2014-03-03 11:18:58
353
原创 USACO Section2.3 Longest Prefix
Longest PrefixIOI'96The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in
2014-01-26 23:27:08
190
原创 USACO Section 2.2 Runaround Numbers
Runaround NumbersRunaround numbers are integers with unique digits, none of which is zero (e.g., 81362) that also have an interesting property, exemplified by this demonstration:If you start
2014-01-16 17:38:36
199
转载 面试题之寻找丢失的数字
转载自:http://blog.csdn.net/hhygcy/article/details/4581731据传说是MS/Google等等IT名企业的面试题:有一组数字,从1到n,中减少了一个数,顺序也被打乱,放在一个n-1的数组里请找出丢失的数字,最好能有程序,最好算法比较快BTW1: 有很多种方法的哦,据说O(n)的方法就不止一种BTW2: 扩展问题,如果丢失了2
2014-01-16 15:23:33
174
转载 动态规划 (Dynamic Programming) 之 最长递增子序列(Longest Increase Subsequence)
转载自:http://blog.csdn.net/hhygcy/article/details/3950158既然已经说到了最长公共子序列,就把这个递增子序列也说了。同样的,这里subsequence表明了这样的子序列不要求是连续的。比如说有子序列{1, 9, 3, 8, 11, 4, 5, 6, 4, 19, 7, 1, 7 }这样一个字符串的的最长递增子序列就是{1,3,4,5,6,7
2014-01-16 13:29:26
186
转载 动态规划 (Dynamic Programming) 之 最长公共子序列(Longest Common Subsequence)
这个问题也是算法导论上提过的问题。注意这个问题是Subsequence不是Substring。substring的话就是子串,子串的要求的连续相等的字符序列,而subsequence不要求连续。比如说ABCD和ABD。他们的longest common subsequence就是ABD。而Longest common substring就是AB。这个问题和Edit Distance是同样的
2014-01-16 13:28:26
216
转载 动态规划 (Dynamic Programming) 之 矩阵链乘法(Matrix Chain Multiplication)
这个问题是动态规划的基础的问题,也是算法导论中讨论过的问题。在这里先简单描述一下。假定有一组矩阵需要做乘法操作。但是我们知道首先矩阵乘法满足了结合律。所以可以按照不同的顺序做乘法。而且不同顺序做乘法最后的乘法次数是不同的。比如〈A1, A2, A3〉分别是10 × 100, 100 × 5, 和 5 × 50。如果按照((A1 A2)A3)的顺序来计算,就是7500次,但是如果(A1 (A2
2014-01-16 13:27:18
203
转载 动态规划 (Dynamic Programming) 之 背包问题合辑 (Knapsack, Subset Sum, Partition and change making problem )
转载自:http://blog.csdn.net/hhygcy/article/details/3955683背包问题一直是动态规划中的经典问题。这个问题又分成01背包,完全背包,多重背包,分组背包等等。。我在这里只记录下01背包(0-1knapsack)和完全背包(unbounded knapsack)。背包问题的简单描述就是有一个背包和一堆物品。每个物品有自己的大小和价值。我们希望在一
2014-01-16 13:25:35
201
原创 USACO Section2.2 Subset Sums
Subset SumsJRMFor many sets of consecutive integers from 1 through N (1 For example, if N=3, one can partition the set {1, 2, 3} in one way so that the sums of both subsets are identical:{
2014-01-16 13:20:51
182
原创 USACO Section2.2 Preface Numbering
Preface NumberingA certain book's prefaces are numbered in upper case Roman numerals. Traditional Roman numeral values use a single letter to represent a certain subset of decimal numbers. Here
2014-01-16 10:05:11
202
原创 USACO Section2.1 Hamming Codes
Hamming CodesRob KolstadGiven N, B, and D: Find a set of N codewords (1 <= N <= 64),each of length B bits (1 <= B <= 8), such that each of the codewordsis at least Hamming distance of D (1 <= D
2014-01-14 16:13:22
186
原创 USACO Section2.1 Healthy Holsteins
Healthy HolsteinsBurch & KolstadFarmer John prides himself on having the healthiest dairy cowsin the world. He knows the vitamin content for one scoop of eachfeed type and the minimum daily vita
2014-01-14 15:09:41
202
原创 USACO Section2.1 Sorting a Three-Valued Sequence
Sorting a Three-Valued Sequence IOI'96 - Day 2Sorting is one of the most frequently performed computational tasks.Consider the special sorting problem in which the records to be sortedhave at
2014-01-14 10:56:09
185
原创 USACO Section2.1 Ordered Fractions
Ordered FractionsConsider the set of all reduced fractions between 0 and 1 inclusivewith denominators less than or equal to N.Here is the set when N = 5:0/1 1/5 1/4 1/3 2/5 1/2 3/5 2/3 3/4 4
2014-01-13 16:57:11
197
原创 USACO Section2.1 The Castle
The CastleIOI'94 - Day 1In a stroke of luck almost beyond imagination, Farmer John wassent a ticket to the Irish Sweepstakes (really a lottery) for hisbirthday. This ticket turned out to have on
2014-01-13 15:00:00
223
原创 USACO Section2.1 The Castle
The CastleIOI'94 - Day 1In a stroke of luck almost beyond imagination, Farmer John wassent a ticket to the Irish Sweepstakes (really a lottery) for hisbirthday. This ticket turned out to have on
2014-01-13 14:45:24
81
原创 USACO Section1.5 Checker Challenge
Checker ChallengeExamine the 6x6 checkerboard below and note that the six checkersare arranged on the board so that one and only one is placed in eachrow and each column, and there is never more
2014-01-11 16:33:41
266
原创 USACO section1.5 Superprime Rib
Superprime RibButchering Farmer John's cows always yields the best prime rib. Youcan tell prime ribs by looking at the digits lovingly stamped acrossthem, one by one, by FJ and the USDA. Farmer
2014-01-10 18:11:17
201
原创 USACO Section1.5 Prime Palindromes
Prime PalindromesThe number 151 is a prime palindrome because it is both a prime numberand a palindrome (it is the same number when read forward as backward).Write a program that finds all prime
2014-01-10 17:30:09
204
原创 USACO Section1.5 Number Triangles
Number TrianglesConsider the number triangle shown below. Write a program thatcalculates the highest sum of numbers that can be passed on a route thatstarts at the top and ends somewhere on the
2014-01-10 15:42:44
174
原创 USACO Section1.4 Mother's Milk
Mother's MilkFarmer John has three milking buckets of capacity A, B, and C liters.Each of the numbers A, B, and C is an integer from 1 through 20,inclusive. Initially, buckets A and B are empty
2014-01-10 11:26:41
183
原创 USACO Section1.4 Arithmetic Progressions
Arithmetic ProgressionsAn arithmetic progression is a sequence of the form a, a+b,a+2b, ..., a+nb where n=0,1,2,3,... . For this problem, a is anon-negative integer and b is a positive integer.
2014-01-09 17:29:19
170
原创 USACO Section1.4 The Clocks
The ClocksIOI'94 - Day 2Consider nine clocks arranged in a 3x3 array thusly:|-------| |-------| |-------| | | | | | | | |---O | |---O | | O |
2014-01-09 15:27:20
196
原创 USACO Section1.4 Packing Rectangles
Packing RectanglesIOI 95The six basic layouts of four rectanglesFour rectangles are given. Find the smallest enclosing (new)rectangle into which these four may be fitted without overlapping.
2014-01-06 17:26:00
209
原创 USACO Section1.3 Prime Cryptarithm
Prime CryptarithmThe following cryptarithm is a multiplication problem that can besolved by substituting digits from a specified set of N digits into thepositions marked with *. If the set of pr
2014-01-06 11:22:45
177
原创 USACO Section1.3 Calf Flac
Calf FlacIt is said that if you give an infinite number of cows an infinitenumber of heavy-duty laptops (with very large keys), that they willultimately produce all the world's great palindromes
2014-01-05 22:32:47
272
原创 USACO Section1.3 Barn Repair
Barn RepairIt was a dark and stormy night that ripped the roof and gates offthe stalls that hold Farmer John's cows. Happily, many of the cows wereon vacation, so the barn was not completely ful
2014-01-04 23:46:23
218
原创 USACO Section1.3 Mixing Milk
Mixing MilkSince milk packaging is such a low margin business, it is importantto keep the price of the raw product (milk) as low as possible. HelpMerry Milk Makers get the milk they need in the
2014-01-04 14:51:58
203
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人