
算法与数据结构
iteye_19635
这个作者很懒,什么都没留下…
展开
-
计算几何相关知识及基本算法
/* 计算几何相关知识及基本算法 */ #i nclude <stdio.h> #i nclude <math.h> #i nclude <stdlib.h> #define MaxNode 100 // 自定义常量,类型及通用函数 const double eps = 1e-6; typedef struct TPoint { ...原创 2008-12-20 19:31:11 · 115 阅读 · 0 评论 -
区间图着色问题(Interval-graph coloring) 调度所有区间
问题: 用很多教室对一组活动进行调度,希望所用的教室数最少。 算法: 对活动时间按开始、结束时间排序(2n个元素)。 建立2个list,第一个list放已使用过的教教室,记做BusyList ,第二个list放未使用的教室FreeList , 对某个时间t, 1. 如果t是某活动 i 的开始时间,在未使用的教室FreeList 中选择教室给 i ,然后把该教室加 入到已使用...2008-11-09 16:12:03 · 902 阅读 · 0 评论 -
求2个有序数组都是N长的,求第K大的(假设数组没有重复)
/* 求2有序N长数组,第K大的数 */ #include <stdio.h> #include <iostream> #include <assert.h> #include <algorithm> #define min(x,y) (x)<(y) ? (x) : (y) #define max(x,y) (x)>(y) ?...2008-11-02 14:19:18 · 116 阅读 · 0 评论 -
Shell Sort
#include <stdio.h> void ShellSort(int A[], int n) { int gap; for(gap=n/2; gap>0; gap/=2) { for(int i=gap; i<n; i++) { for(int j=i; j>=0; j-=gap) { if(A[j]<A[j-gap]...2008-10-29 21:14:53 · 111 阅读 · 0 评论 -
Find the mdian int two Arrays
Let X [1 .. n ] and Y [1 .. n ] be two arrays, each containing n numbers already in sorted order. Give an O (lg n )-time algorithm to find the median of all 2n elements in arrays X and Y . #i...2008-10-29 20:21:01 · 113 阅读 · 0 评论 -
Couting Sort
CoutingSort #include <stdio.h> #include <stdlib.h> void CountingSort(int A[], int B[], int k,int n) { int * C; C=(int *)calloc(k,sizeof(int)); for(int i=0;i<n; i++) { C[A[i]]+...2008-10-29 11:16:44 · 108 阅读 · 0 评论 -
quick sort program
#include <stdio.h> #include <stdlib.h> void swap(int & a,int & b) { int temp=a; a=b; b=temp; } int QuickSort_Partition(int A[],int p, int r) { //随机选值 int s_max=rand()%(r-p+...2008-10-28 20:50:39 · 106 阅读 · 0 评论 -
Master method/Master theorem
According to my understand,Detail to see OLCRS chapter 4. Master Method: T(n)=aT(n/b)+f(n) base Master Theorem, the Solution can be divide into 3 cases.Each case compare N^(loga/lo...2008-10-14 17:11:08 · 267 阅读 · 0 评论 -
对于给定的整数,求出删除该整数中的一个数字后得到的最小值
对于给定的整数,求出删除该整数中的一个数字后得到的最小值. 比如,1214 ,去掉2,得到的结果是114为最小值. 算法: 删除数字中的极大值( 左边的数字递增,右边紧邻的数字是减少的或者本身为最后一位。例如:1214 中的2 ; 122543中的5; 1334中的4) 证明:假设极大值为第i位,记为X[i].分2种情况, 1 。如果删除 i 左边的某位记第j位,即删除...2009-06-06 23:31:04 · 919 阅读 · 0 评论 -
KMP算法:基于自动机的理解
KMP 算法学习总结 KMP 算法看似简单,其实想要完全理解还是有困难的。 KMP 其实可以搜索过程可以看成是一个自动机,分为 2 部分,第一部分自动机的构造 ( 对应一般的说法就是失效函数,转移函数, overlap 函数 ) ,第二部分在自动机上搜索过程。 举个例子: 目标串味 T = acabaabaabcacaabc; ...2009-06-04 17:10:42 · 453 阅读 · 0 评论 -
KMP算法实现(参考Wiki上算法描述)
#include <iostream> using namespace std; /** * paramter pat:待匹配的字符串 * T: 返回的table * **/ void kmp_table(const char * W, int T[]) { int pos = 2; //当前查找的位置 int cnd = 0; //当前查找的前缀字串的位...2009-06-02 21:39:30 · 150 阅读 · 0 评论 -
最少拦截系统
描述某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统。但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度。某天,雷达捕捉到敌国的导弹来袭。由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹。怎么办呢?请帮助计算一下最少需要多少套拦截系统?输入输入若干组数据(不超过100组),每组数据一行,分别为:导弹总个数(正整数,...2009-12-16 15:12:25 · 250 阅读 · 0 评论 -
如何用加1操作实现减法
转载自 http://www.matrix67.com/blog/archives/944/trackback 设想这样一个计算机系统,它只支持以下几个操作: 1. 定义变量、给变量赋值; 2. 变量自身加一; 3. 令一段语句循环执行指定的次数。 这个系统只处理且只能处理0和正整数。系统不存在“溢出”的问题。 注意这个系统没有比较运...原创 2009-08-17 10:16:22 · 244 阅读 · 0 评论