随笔分类 - 3> 基础算法
摘要:examination questions Implement int sqrt(int x). Compute and return the square root of x. Example sqrt(3) = 1 sqrt(4) = 2 sqrt(5) = 2 sqrt(10) = 3 sqr
阅读全文
摘要:examination questions Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth dist
阅读全文
摘要:examination questions Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting wi
阅读全文
摘要:examination questions Description: Count the number of prime numbers less than a non-negative number, n References: How Many Primes Are There? Sieve o
阅读全文
摘要:从运行时间上来看本题的运算提升过程: 40秒 --> 24秒 --> 1.5秒 --> 0.1秒,01.秒 与 40秒的差距是400倍,一个好的算法和解决方案,可以节省400倍的时间!
那么,如何从一开始就做到尽量防止存在后顾之忧呢?我思考如下:
第一,要对问题的本质有非常明确的了解,不能只知其一不知其二。比如上面我的解题过程,仅仅知道质数的判断定义,并没有对里面存在的规律进行深入了解,造成了解题失败。
第二,在解决问题之前,尽可能的思考多种解法方案,记录下来,分析各种方案在时间效率,空间使用度的优劣。再选上符合要求的最好的方案去实施。切忌想到一个方法,它可以解决问题,但是很有可能不是最优方法,但是为了快速解决问题而拒绝思考,最后可能会照成不必要麻烦。(重写代码,代价更高),这个道理可能大家都懂,但是很少人真正有这样去做一件事情。
......
阅读全文
摘要:测试: demo.cpp #include "trituple.h" #include <iostream> using namespace std; int main(){ Trituple data1; Trituple data2; cout << "功能演示 " << endl; cout
阅读全文
摘要:链栈基本操作头文件代码: typedef struct node{ DataType data; struct node *next; }LStackNode, *LinkStack; void InitStack(LinkStack *top){ if ((*top = (LinkStack)ma
阅读全文

浙公网安备 33010602011771号