随笔分类 -  Algorithm

摘要:写本篇主要是为了将基础知识梳理一遍,天天加一些基本东西,以后复习时可以返回来看看。数据结构&&基础算法:基本算法: 二分查找二叉树: 二叉树的各种遍历位操作:排序:排序算法总结图论: 总结RMQ : ST 阅读全文
posted @ 2013-09-26 16:46 冰点猎手 阅读(145) 评论(0) 推荐(0) 编辑
摘要:1 prim 算法 O(n2) 贪心/* 最小生成树Prim 算法: 贪心思想,随机选择一个点当做最小生成树的初始节点,然后把图的顶点分成A集合(含初始节点), B集合(剩余节点)每次选择A集合中的点到B集合中点的最短距离的边,然后用加入的点去松弛A集合点到B集合点的距离信息。不断迭代, 最终得到最小生成树。*/struct Edge{ int start_, end_; float weight_;};void prim(vector> &map, Edge *&mist){ int n = map.size(); if(n > &grap... 阅读全文
posted @ 2013-09-26 16:45 冰点猎手 阅读(175) 评论(0) 推荐(0) 编辑
摘要:对于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^k) T(n) = O(n^k); 阅读全文
posted @ 2013-09-21 20:19 冰点猎手 阅读(304) 评论(0) 推荐(0) 编辑
摘要:int minthree(int a1, int a2, int a3){ a1 = a1 q2, q3, q5; int res = 1; q2.push(2); q3.push(3); q5.push(5); while(index > 1){ --index; int tp = minthree(q2.front(), q3.front(), q5.front()); if(tp == q2.front()){ q2.pop(); q2.push(tp*2); q3.push(tp*3); q5.push(tp*5); }else if(tp == q3.fro... 阅读全文
posted @ 2013-09-16 16:22 冰点猎手 阅读(209) 评论(0) 推荐(0) 编辑
摘要:const int g_maxlen = 10;char * g_strCombine1 = new char[g_maxlen*2 +1];char * g_strCombine2 = new char[g_maxlen*2 +1];int compare(const void *str1, const void *str2){ strcpy(g_strCombine1, *(const char **)str1); strcat(g_strCombine1, *(const char **)str2);// important strcpy(g_strCombine2, *(const c 阅读全文
posted @ 2013-09-16 15:26 冰点猎手 阅读(184) 评论(0) 推荐(0) 编辑
摘要:直接插入排序:稳定排序 时间复杂度 O(n2)void insertSort(int data[], int N){ if(N =0 && data[j] > temp){ data[j+1] = data[j]; --j; } if(j != i-1) data[j+1] = temp; } }View Code二分法插入排序:稳定排序 O(n2)void binSort(int data[], int N){ if(N >1 + right>>1 ; ... 阅读全文
posted @ 2013-09-03 19:42 冰点猎手 阅读(269) 评论(0) 推荐(0) 编辑
摘要:/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */// 三种遍历的递归实现void preOrder(TreeNode * root){ if(NULL == root ) return ; visit(root->val); preOrder(root->left); pr... 阅读全文
posted @ 2013-04-10 20:12 冰点猎手 阅读(167) 评论(0) 推荐(0) 编辑
摘要:There are two sorted arrays A and B of size m and n respectively. Find the median of the two sorted arrays. The overall run time complexity should be 阅读全文
posted @ 2013-03-28 11:53 冰点猎手 阅读(176) 评论(0) 推荐(0) 编辑
摘要:方法一: dijstra + DFSView Code 1 #include <stdio.h> 2 #include <string.h> 3 4 const int INF = 10000000 ; 5 int map[505][505]; 6 int dist[505]; 7 int teamNum[505]; 8 int visit[505]; 9 int N , M, C1, C2; 10 int pathNum, maxTeamNum; 11 void initApp() 12 { 13 int temp, m, n, i, j; 14 me... 阅读全文
posted @ 2013-03-24 18:24 冰点猎手 阅读(274) 评论(0) 推荐(0) 编辑
摘要:原理如下:(本方法有问题,希望看的朋友注意,不要误导了你们) 判断的方法如下图所示,首先找到最西边的点,在图中是3号点,则从该点前一个点开始的连续三个点(在图中是2、3、4三个点)的排序就代表了整个拐点序列的排序;而这三个点的排序可以通过比较坐标方位角判断出来:若中间点到前点的坐标方位角小于中间点到后点的坐标方位角,则为逆时针排列,反之为顺时针排列。在图中α32小于α34,因此为逆时针排列。注:“坐标方位角”是测量学名词,指从坐标系北方向顺时针转向有向直线的夹角。 上述方法适用范围有限,而且算法本身不是很鲁棒!我们知道,对于给定的一个走向,如果从正面看是顺时针,从反面看则为逆时针。所以给定一个 阅读全文
posted @ 2011-10-20 12:32 冰点猎手 阅读(2495) 评论(2) 推荐(0) 编辑

点击右上角即可分享
微信分享提示