算法
ldanduo
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
求两个整数最大公约数
#includeusing namespace std;//方法一辗转相除法求最大公约数int gcd(int x, int y){ return (!y)?x:gcd(y, x%y);}//方法二减法进行求最大公约数但迭代次数增加int gcd1(int x, int y){ if ( x < y ) return gcd1(y, x); if ( y == 0原创 2012-09-26 16:05:09 · 638 阅读 · 0 评论 -
堆排序heapsort
#includeusing namespace std;void AdjustHeap(int Array[], int spoint, int len){ while ( ( 2 * spoint + 1 ) < len ) { int mpoint = 2 * spoint + 1; if ( (2 * spoint + 2) < len ) { if ( Ar原创 2012-09-26 13:46:23 · 490 阅读 · 0 评论 -
大数乘法
转载:http://blog.youkuaiyun.com/taesimple/article/details/7554086这里的大数是指:超过计算机变量(包括long long)表示范围的数因此我们考虑用字符串保存两个乘数以及结果,按位相乘需要注意两点:记两乘数分别为X和Y,其中X有m位,Y有n位,则Z=X*Y可能有m+n位或m+n-1位。如10*10=100, 99*99=980转载 2012-10-19 23:15:34 · 603 阅读 · 0 评论 -
删除字符串空格
#includeusing namespace std;void del_space(char* str) { for (int i = 0, j = 0; str[i] = str[j++]; str[i] != ' ' && ++i) cout<<str<<endl;}int main(void){ char str[] = "hello anduo nin原创 2012-11-04 22:42:02 · 697 阅读 · 0 评论 -
删除字符串中多余的空格(只保留一个空格)
#include#include#includeusing namespace std;void f(char* s1, char* s2){ while (*s1 == ' ') { s1++; } while (*s2 = *s1++) { if (*s2 != ' ' || *s1 != ' ') {原创 2012-11-04 23:08:21 · 3516 阅读 · 0 评论 -
求两个等长升序序列的中位数
转载地址:http://blog.youkuaiyun.com/algorithm_only/article/details/7084478【版权声明:转载请保留出处:blog.youkuaiyun.com/algorithm_only。邮箱:liuy0711@foxmail.com】1. 算法要求一个长度为L(L≥1)的升序序列S,处在第L / 2(若为小数则去掉小数后加1)个位置的数称为S转载 2012-11-04 23:36:14 · 989 阅读 · 0 评论 -
字符串全排序问题
#includeusing namespace std;void Swap(char &a, char &b){ char temp; temp = a; a = b; b = temp;}void Perm(char s[], int k, int m){ if(k==m) cout<<s<<endl; els原创 2012-11-18 00:51:33 · 1056 阅读 · 2 评论 -
求一个字符串中连续出现次数最多的字串
#include#include#includeusing namespace std;pair fun(const string &str){ vector substrs; int maxcount = 1; int count =1; string substr; int i, len = str.length(); for (i = 0; i < len; ++i)原创 2012-11-18 00:29:06 · 794 阅读 · 0 评论 -
求两个字符串的最长的连续公共子串
转载地址:http://blog.youkuaiyun.com/shandianling/article/details/7913818这与求两个字符串的公共子序列要区分开,见http://blog.youkuaiyun.com/shandianling/article/details/7888050但 求你方法与求公共子序列类似,而且要简单一点。方法:动态规划.循环遍历两个字符串,查找当s1转载 2012-12-10 10:39:40 · 1256 阅读 · 0 评论 -
动态规划求编辑距离
参考:http://topic.youkuaiyun.com/u/20110607/07/63dec342-b2ec-4f5c-82a8-044531d78392.html http://qinxuye.me/article/get-edit-distance-by-dynamic-programming///动态规划://f[i,j]表示src[0...i]与dst[0.原创 2012-10-18 10:41:04 · 717 阅读 · 0 评论 -
快速排序QuickSort
#includeusing namespace std;int AdjustArray(int s[], int l, int r){ int i = l; int j = r; int temp = s[l]; while ( i < j ) { while ( s[j] >= temp && j > i) { j--; } if ( j > i )原创 2012-09-26 09:36:09 · 705 阅读 · 0 评论 -
二分查找
#include//date 2013.10.15//reference http://blog.youkuaiyun.com/v_july_v/article/details/7093204using namespace std;int binary_search(int array[], int n, int value){ int left =0; int right = n-1;转载 2012-10-15 10:30:06 · 652 阅读 · 0 评论 -
求数组的子数组之和的最大值
//时间复杂度为O(N)#includeusing namespace std;int max(int x, int y){ return (x > y) ? x : y;}int MaxSum(int Array[], int n){ int nStart = Array[n-1]; int nAll = Array[n-1]; for (int i = n-原创 2012-09-26 21:21:33 · 696 阅读 · 0 评论 -
一个fork的面试题
转载:http://coolshell.cn/articles/7965.html前两天有人问了个关于Unix的fork()系统调用的面试题,这个题正好是我大约十年前找工作时某公司问我的一个题,我觉得比较有趣,写篇文章与大家分享一下。这个题是这样的:题目:请问下面的程序一共输出多少个“-”?#include #include #include int main(v转载 2012-10-06 21:26:06 · 682 阅读 · 0 评论 -
产生1000w不重复的数字
//purpose:产生随机的不重复的测试数据//copyright@ 2010.05.30 july //参考:http://blog.youkuaiyun.com/v_JULY_v/article/details/6451990//1000w数据量,要保证生成不重复的数据量;//data: 2012.10.9#include#include#include//文件操作用到这个头文件#原创 2012-10-08 23:30:31 · 1021 阅读 · 0 评论 -
bitmap位图方案解决海量数据文件排序的问题
参考:http://blog.youkuaiyun.com/v_JULY_v/article/details/6451990产生文件10^7个数据文件data.txt:http://blog.youkuaiyun.com/ldanduo/article/details/8050484//copyright@ yansha July、2010.05.30。 //位图方案解决10^7个数据量的文件的排序原创 2012-10-09 22:51:44 · 974 阅读 · 0 评论 -
链表测试程序
//#include #include#include //链表结构体using namespace std;typedef struct Node { int data; struct Node* next; }LNode,*Linklist; //输入链表的数据int read(void) { int a=0; //scanf("%d原创 2012-10-10 13:01:02 · 1275 阅读 · 0 评论 -
表达式前后缀表达形式 [zz]
装载:http://blog.youkuaiyun.com/whatforever/article/details/673853835,15,+,80,70,-,*,20,/ //后缀表达方式(((35+15)*(80-70))/20)=25 //中缀表达方式 /,*,+,35,15,-,80,70, 20转载 2012-10-12 08:53:46 · 792 阅读 · 0 评论 -
对内存重叠的深入认识
装载:http://blog.youkuaiyun.com/feitianxuxue/article/details/7195158内存重叠:拷贝的目的地址在源地址范围内。所谓内存重叠就是拷贝的目的地址和源地址有重叠。在函数strcpy和函数memcpy都没有对内存重叠做处理的,使用这两个函数的时候只有程序员自己保证源地址和目标地址不重叠,或者使用memmove函数进行内存拷贝。memmove转载 2012-10-12 18:34:20 · 583 阅读 · 0 评论 -
求整数1……n中0的个数
#includeusing namespace std;int Count( int n){ int iNum = 0; cout<<n<<":"; while ( n !=0 ) { iNum += (n % 10 == 0 )? 1 : 0; n = n / 10; } cout<<iNum<<endl; return iNum;}int main(int a原创 2012-09-26 09:40:18 · 2577 阅读 · 0 评论 -
T(n) = 25T(n/5)+n^2的时间复杂度?
原文地址:T(n) = 25T(n/5)+n^2的时间复杂度 作者:djkpengjun主定理:对于T(n) = a*T(n/b)+c*n^k;T(1) = c 这样的递归关系,有这样的结论: if (a > b^k) T(n) = O(n^(logb(a)));logb(a)b为底a的对数if (a = b^k) T(n) = O(n^k*logn);if (a < b^转载 2012-10-06 17:35:08 · 6717 阅读 · 1 评论 -
已知树的前序遍历和中序遍历,求后序遍历的方法(转)
/* 树中已知先序和中序求后序。 如先序为:abdc,中序为:bdac . 则程序可以求出后序为:dbca 。此种题型也为数据结构常考题型。 算法思想:先序遍历树的规则为中左右,则说明第一个元素必为树的根节点,比如上例中的a就为根节点,由于中序遍历为:左中右,再根据根节点a,我们就可以知道,左子树包含元素为:db,右子树包含元素:c,再把后序进行转载 2012-10-18 12:01:06 · 1424 阅读 · 0 评论
分享