algorithms&data structure
浪漫代码
这个作者很懒,什么都没留下…
展开
-
区间求并集c++实现
#include #define NULL 0using namespace std;struct section//每个小区间{ double start; double end; bool isuse;};struct whole_section//区间并集{ section* sec; int length; int size;原创 2013-08-21 22:02:03 · 3618 阅读 · 1 评论 -
编辑距离问题c语言实现
所谓编辑距离是指一个字符串转化成另外一个字符串所需要的最少编辑次数。允许的编辑方式包括:1)增加一个字符2)删除一个字符3)用一个字符替换原来的字符解决的方法当然是动归了。首先研究子问题,假设两字符串A,B。1)、当两个字符串长度为1时,若字符相同则编辑距离为0;若不同则为1;2)、当一个A的长度为1,B的长度为N时,先利用1)的方法计算A和B第一个字符的编辑距离为t,然后原创 2013-08-10 21:03:57 · 4072 阅读 · 0 评论 -
判断三角形与点的关系的一种实现
在二维坐标系中,对三角形ABC和某一点P,设A(x1,y1)、B(x2,y2)、C(x3,y3)、P(x,y),如果向量AB×AP、BC×BP、CA×CP指向同一方向,则说明P点在三角形内部。#include using namespace std;struct Triangle{ int x1; int y1; int x2; int y2; int x3; int y3;原创 2013-08-21 21:39:29 · 689 阅读 · 0 评论 -
动态规划之滑雪问题c++实现
问题描述: Michael喜欢滑雪百这并不奇怪, 因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道在一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3 4 516 17 18 19 615 24 25 20 7原创 2013-08-22 23:32:04 · 6161 阅读 · 0 评论 -
KMP算法c实现
讲解详见matrix67大神博客,直接上代码了。#include #include int next[100];int pre_processing(char* s){ next[0]=0; int i,j; for(i=1;i<strlen(s);i++) { j=next[i-1]; while(j!=0&&s[j]!=s[i]) j=nex原创 2013-08-27 01:43:55 · 603 阅读 · 0 评论 -
hdu2222及易错数据(AC自动机)
RT.#include #include using namespace std;const int kind=26;struct node{ node* fail; node* next[kind]; int count;//是否为该单词的最后一个节点 node(){ fail=NULL; count=0; memset(next,NULL,si原创 2013-08-29 13:02:36 · 563 阅读 · 0 评论 -
快排、归并排序、堆排序的实现
#include using namespace std;//quick_sortvoid quick(int *a,int start,int end){ if (start>=end) return; int startx=start; int endx=end; int key=a[start]; while(start<end) {原创 2013-09-04 16:40:07 · 509 阅读 · 0 评论