摘要:堆排序:由三个函数组成:Max_heapify ( int A[] ,int i ,int heap_size)//堆化 T(n)=log(n);Build_max_heap(int A[],int heap_size)//建堆 T(n)=n ;Heap_sort(int A[],int le...
阅读全文
摘要:大数加法: 1 #include 2 #include 3 #include 4 #define M 100 5 char *add(char s1[],char s2[]); 6 int main(){ 7 char s1[M],s2[M],*s; //此时不能使用strle...
阅读全文
摘要:厨师写了一些文字在一张纸上,现在他想知道有多少洞在文本中。什么是一个洞?如果您认为纸为平面和一个字母为平面上的曲线,那么每个字母划分平面成区域。例如字母“A”,“D”,“O”,“P”,“R”分裂平面分成两个区域,所以我们说每个字母有一个孔。同样的,字母“B”有两个孔和字母如“C”,“E”,“F”,“...
阅读全文
摘要:一个头疼的程序;计算100以内的阶乘。这是我的程序,可计算10000以内的阶乘: 1 /*Small factorials*/ 2 3 #include 4 int fact(int n); 5 void print(int len); 6 7 int F[200]; 8 9 int mai...
阅读全文
摘要:Strassen矩阵乘法是通过递归实现的,它将一般情况下二阶矩阵乘法(可扩展到n阶,但Strassen矩阵乘法要求n是2的幂)所需的8次乘法降低为7次,将计算时间从O(nE3)降低为O(nE2.81)。矩阵C = A*B,可写为C11 = A11B11 + A12B21C12 = A11B12 + ...
阅读全文
摘要:/*求子数组的最大和题目描述:输入一个整形数组,数组里有正数也有负数。数组中连续的一个或多个整数组成一个子数组,每个子数组都有一个和。求所有子数组的和的最大值。要求时间复杂度为O(n)。例如输入的数组为1, -2, 3, 10, -4, 7, 2, -5,和最大的子数组为3, 10, -4, 7, ...
阅读全文
摘要:斐波那契数列的几种不同的算法实现: 1 #include "stdio.h" 2 #include "math.h" 3 4 5 int Fibonacci1(int n,int acc1,int acc2)//另一种新的递归方法T(n)=O(n) 6 { 7 if(n==0)retur...
阅读全文
摘要:1 #include 2 void insertsort(int *A,int p,int r){ 3 //插入排序 4 int i,j,k; 5 for(i=p;ip&&j<A[k-1]){ 8 A[k]=A[k-1]; 9 ...
阅读全文
摘要:1 #include 2 //#include 3 int jiecheng(int i){ 4 //①算n! 5 if(i==1)return 1; 6 return i*jiecheng(i-1); 7 } 8 int Fibonacci(int i){ 9 /...
阅读全文
摘要:1 #include 2 void MERGE(int *A,int p,int q,int r){ 3 int i,j,k; 4 int *B=malloc((r-p+1)*sizeof(int)); 5 i=p;j=q+1;k=0; 6 while(i<=q&&...
阅读全文