算法
文章平均质量分 78
DrakePassge
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
对二分查找程序的一次测试
本文内容来源于《编程珠玑》第二版5.2节。 先看一段程序: public class ErrirBinary { static int array[] = new int[] { 0, 1, 2, 3, 4 }; public static int BinarySearch(int number) { int start = 0, middle, end原创 2015-01-07 09:58:47 · 695 阅读 · 0 评论 -
百炼OJ1007
描述现在有一些长度相等的DNA串(只由ACGT四个字母组成),请将它们按照逆序对的数量多少排序。逆序对指的是字符串A中的两个字符A[i]、A[j],具有i A[j] 的性质。如字符串”ATCG“中,T和C是一个逆序对,T和G是另一个逆序对,这个字符串的逆序对数为2。输入第1行:两个整数n和m,n(0第2至m+1行:每行是一个长度为n的字符串输出按逆原创 2016-01-15 14:50:34 · 1039 阅读 · 0 评论 -
百炼OJ1005
描述Fred Mapper is considering purchasing some land in Louisiana to build his house on. In the process of investigating the land, he learned that the state of Louisiana is actually shrinking by 50 squ原创 2016-01-15 14:34:30 · 635 阅读 · 0 评论 -
百炼OJ1004
描述Larry今年毕业并找到了一份工作。他赚很多钱,但似乎总是不够。Larry认为他需要控制他的投资以解决自己的财务问题。Larry拿到了自己的银行账户详单,想看看自己有多少钱。请帮助Larry写一个程序,通过过去12个月中每月的月末结余,计算平均结余。输入输入包含12行,每行包含一个数,为某个月的结余。每个数都是不大于1,000,000的正数,保留两位小数,省略"$"符。原创 2016-01-15 14:31:13 · 2826 阅读 · 0 评论 -
百炼OJ1002
描述英文字母(除Q和Z外)和电话号码存在着对应关系,如下所示:A,B,C -> 2D,E,F -> 3G,H,I -> 4J,K,L -> 5M,N,O -> 6P,R,S -> 7T,U,V -> 8W,X,Y -> 9标准的电话号码格式是xxx-xxxx,其中x表示0-9中的一个数字。有时为了方便记忆电话号码,我们原创 2016-01-14 00:09:43 · 651 阅读 · 0 评论 -
百炼OJ1001
描述Problems involving the computation of exact values of very large magnitude and precision are common. For example, the computation of the national debt is a taxing experience for many computer sy原创 2016-01-13 19:13:46 · 706 阅读 · 0 评论 -
百炼OJ1009
描述IONU Satellite Imaging, Inc. records and stores very large images using run length encoding. You are to write a program that reads a compressed image, finds the edges in the image, as described be原创 2016-01-19 11:38:05 · 858 阅读 · 0 评论 -
百炼OJ1006
描述Some people believe that there are three cycles in a person's life that start the day he or she is born. These three cycles are the physical, emotional, and intellectual cycles, and they have peri原创 2016-01-15 14:35:57 · 481 阅读 · 0 评论 -
编程珠玑第二版第三章习题(Java)
1 定义三个数组,分别存储某一阶段收入起点,税率以及已有税收。代码:public class Tax { static float[] rate = new float[58];// 税率 static double[] start = new double[58];// 收入起点 static double[] tax = new double[58];// 已有税 pub原创 2015-01-06 14:51:21 · 839 阅读 · 0 评论 -
编程珠玑第二版第五章习题(Java)
1 (此段内容来自原书,在此向原作者表示感谢)When I write large programs, I use long names (ten or twenty characters) for my global variables. This column uses short variable names such as x, n and t. In most software proj原创 2015-01-07 10:43:34 · 1114 阅读 · 0 评论 -
编程珠玑第二版第四章习题(Java)
>1 初始限定 上下限范围,下限不会变小,上限不会变大,保证不会越界。2 二分法改进,第一次找到指定数字后记录该位置,姑且叫他location,之后锲而不舍的向前二分寻找,因为找第一次出现,所以肯定不会往后找,直到start+1=end。这个时候返回location值。public class Number { static int[] array = new int[] { 1,原创 2015-01-06 16:44:05 · 734 阅读 · 0 评论 -
编程珠玑第二版第八章习题(Java)
1 书上说要参考某论文,不明觉厉。3 这个大概是个数列求和,没啥可说的。4 每一个数字都是[-1,1]之间随机取的一个数字,服从均匀分布,假设这个数组足够大,那么每个数字都可能出现,为此可以推测最大子段和期望是1.5 cumarr声明成 float*cumarr,则赋值 cumarr=realarray+1;意味着cumarr[-1]指向realarray[0]。9 maxsofa原创 2015-01-12 10:06:57 · 790 阅读 · 0 评论 -
编程珠玑第二版第六章习题(Java)
这一章的程序性能分析通常在数据结构第一张就会讲到。3 写个程序测试一下public class TimeTest { public static void main(String[] args) { // TODO 自动生成的方法存根 long time1, time2, time3, time4; float a = 0; double b = 0; float x原创 2015-01-08 09:43:43 · 1279 阅读 · 0 评论 -
最长递增子序列 O(NlogN)算法
原博客地址:http://www.felix021.com/blog/tb.php?t=1587&extra=f46f2今天回顾WOJ1398,发现了这个当时没有理解透彻的算法。看了好久好久,现在终于想明白了。试着把它写下来,让自己更明白。最长递增子序列,Longest Increasing Subsequence 下面我们简记为 LIS。排序+LCS算法 以及 DP算法就转载 2015-01-10 09:50:15 · 508 阅读 · 0 评论 -
动态规划:从新手到专家
作者:Hawstein出处:http://hawstein.com/posts/dp-novice-to-advanced.html声明:本文采用以下协议进行授权: 自由转载-非商用-非衍生-保持署名|Creative Commons BY-NC-ND 3.0 ,转载请注明作者及出处。前言本文翻译自TopCoder上的一篇文章: Dynamic Programmin转载 2015-01-09 20:40:11 · 525 阅读 · 0 评论 -
百炼OJ1003
描述How far can you make a stack of cards overhang a table? If you have one card, you can create a maximum overhang of half a card length. (We're assuming that the cards must be perpendicular to the原创 2016-01-14 12:41:07 · 533 阅读 · 0 评论
分享