算法
南七程序员毛毛
试着用物理学第一原理去看世界
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
哈夫曼编码
我大一时实现的哈弗曼编码,用的是静态方法(只能统计在ascII中出现的字符)原创 2015-04-01 14:31:35 · 611 阅读 · 0 评论 -
Ford&Fulkerson 最大流问题
#includeusing namespace std;#define MAXN 10000003int n,sink;bool Vis[100];__int64 C[100][100],F[100][100];struct list{int value;bool dir;};struct stack{int top;list原创 2015-04-20 15:28:00 · 694 阅读 · 0 评论 -
Prim算法求最小生成树
#includeusing namespace std;#define MAXN 10002int Map[100][100],Vis[100],Low[100],Tree[100];int n;void Prim(){int i,j,p;int minc;memset(Vis,0,sizeof(Vis));Vis[0]=1;for( i=1原创 2015-04-20 15:30:39 · 864 阅读 · 0 评论 -
用匈牙利算法求二分图的最大匹配
1, 用匈牙利算法求二分图的最大匹配算法轮廓:(1)置M为空(2)找出一条增广路径P,通过取反操作获得更大的匹配M’代替M(3)重复(2)操作直到找不出增广路径为止程序文件夹:22222#include #include using namespace std; const int MAXN = 100 ;原创 2015-04-20 15:34:16 · 780 阅读 · 0 评论 -
基于BFS的最大流算法(Edmonds)
#includeusing namespace std;#define MAXN 10003 bool Vis[100];int Map[100][100],F[100][100],n,Target,Min;struct queen{int top;int end;int node[100];}f;struct vertex{原创 2015-04-20 15:30:40 · 877 阅读 · 0 评论 -
求图的切割点
#includeusing namespace std;int Num[100],Low[100],Father[100];bool Mark[100],Map[100][100],Cutpoint[100];int time,n;void DFS(int x){Mark[x]=true;time++;Low[x]=Num[x]=time;f原创 2015-04-20 15:31:21 · 434 阅读 · 0 评论 -
深搜用栈的实现
#includeusing namespace std;int Map[100][100],n,Target;bool Vis[100];struct stack{int node[100];int top;}f;bool DFS(int x){f.top=1;f.node[f.top]=x;while(f.top){in原创 2015-04-20 15:31:54 · 1661 阅读 · 0 评论 -
关键路径
#include#includeusing namespace std;int Map[100][100],Value[100];bool Mark[100];int n,s,t;//if Max was defined here things will be much different now!int CP(int x){//if(Ma原创 2015-04-20 15:31:20 · 440 阅读 · 0 评论 -
一致性哈希算法及其在分布式系统中的应用
摘要本文将会从实际应用场景出发,介绍一致性哈希算法(Consistent Hashing)及其在分布式系统中的应用。首先本文会描述一个在日常开发中经常会遇到的问题场景,借此介绍一致性哈希算法以及这个算法如何解决此问题;接下来会对这个算法进行相对详细的描述,并讨论一些如虚拟节点等与此算法应用相关的话题。分布式缓存问题假设我们有一个网站,最近发现随着流量增加,服务器压力越来越大转载 2015-08-17 20:47:49 · 709 阅读 · 0 评论 -
Dijkstra算法
#include#includeusing namespace std;#define MAXN 10002int Map[100][100],D[100],n,Target;bool Vis[100];void Dijkstra(int x){Vis[x]=true;int min=MAXN,count;while(!Vis[Targe原创 2015-04-20 15:28:43 · 434 阅读 · 0 评论 -
DFS的时间戳应用
#includeusing namespace std;bool Map[100][100],Vis[100];int d[100],f[100],n,time;void DFS(int x){Vis[x]=1;d[x]=time;for(int i=0;i{if(Map[x][i]&&!Vis[i]){Map[x][i]=0;原创 2015-04-20 15:26:36 · 1551 阅读 · 0 评论 -
BFS 数组模拟队(有向图)
#includeusing namespace std;const int Limit = 400,maxinum = 10000;int data[Limit][Limit],visited[Limit];int N,S,T;int queue[Limit];bool BFS(int S,int m){ int i,open = 1,cl原创 2015-04-01 14:41:16 · 803 阅读 · 0 评论 -
BFS
#include #include using namespace std;struct POSITION { int x, y; bool operator == (const POSITION &oth) const { return x == oth.x && y == oth.y; } bool op原创 2015-04-01 14:42:59 · 529 阅读 · 0 评论 -
DFS (栈改BFS)
#include #include using namespace std;struct POSITION { int x, y; bool operator == (const POSITION &oth) const { return x == oth.x && y == oth.y; } bool op原创 2015-04-01 14:43:45 · 683 阅读 · 0 评论 -
DFS
#include using namespace std;const int maxn = 100;int n, m;int map[maxn][maxn], vis[maxn][maxn];int startx, starty, endx, endy;int dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};原创 2015-04-01 14:45:03 · 594 阅读 · 0 评论 -
深度搜索
#include using namespace std;const int maxn = 100;int n, m;int map[maxn][maxn], sign[maxn][maxn];int startx, starty, endx, endy;int dir[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};boo原创 2015-04-01 14:46:38 · 725 阅读 · 0 评论 -
BFS(迷宫)
#include #include using namespace std;struct POSITION { int x, y; bool operator == (const POSITION &oth) const { return x == oth.x && y == oth.y; } bool op原创 2015-04-01 14:42:44 · 686 阅读 · 0 评论 -
BFS 队 (有向图)
#include#includeusing namespace std;const int Limit = 400,maxinum = 10000;int data[Limit][Limit],visited[Limit]; //data[][]为图的邻接矩阵 visited[i]用于记录起源点到点i的最短路径长度; int N,S,T;原创 2015-04-01 14:40:26 · 583 阅读 · 0 评论 -
欧拉图算法
首先考虑是欧拉图。若从一个顶点出发,利用DFS,将新搜索到的顶点保存到栈顶,并且将走过的边给删除,那么一定能访问到这个初始顶点。因为除起始顶点外其他的顶点若被访问到那么一定能去访问别的顶点。但是起始顶点不同,它是被直接访问的,即没有通过别的顶点去访问它,因此我们一定能找到这样的回路,使得起始顶点和终点是同一顶点,设为v,并且v的所有边都在这条回路上。我们用栈来保存这些顶点(按访问的顺序),如果此时原创 2015-04-20 15:25:19 · 2255 阅读 · 0 评论 -
求最长回文子串,O(n)复杂度
最长回文子串问题—Manacher算法最长回文串问题是一个经典的算法题。0. 问题定义最长回文子串问题:给定一个字符串,求它的最长回文子串长度。如果一个字符串正着读和反着读是一样的,那它就是回文串。下面是一些回文串的实例:12321 a aba abba aaaa tattarrattat(牛津英语词典中最长的回文单词)原创 2016-04-04 13:25:09 · 4586 阅读 · 1 评论
分享