![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
南七程序员毛毛
试着用物理学第一原理去看世界
展开
-
哈夫曼编码
我大一时实现的哈弗曼编码,用的是静态方法(只能统计在ascII中出现的字符)原创 2015-04-01 14:31:35 · 538 阅读 · 0 评论 -
Ford&Fulkerson 最大流问题
#include using namespace std; #define MAXN 10000003 int 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 · 633 阅读 · 0 评论 -
Prim算法求最小生成树
#include using namespace std; #define MAXN 10002 int 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 · 786 阅读 · 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 · 692 阅读 · 0 评论 -
基于BFS的最大流算法(Edmonds)
#include using 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 · 783 阅读 · 0 评论 -
求图的切割点
#include using 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 · 369 阅读 · 0 评论 -
深搜用栈的实现
#include using 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 · 1566 阅读 · 0 评论 -
关键路径
#include #include using 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 · 377 阅读 · 0 评论 -
一致性哈希算法及其在分布式系统中的应用
摘要 本文将会从实际应用场景出发,介绍一致性哈希算法(Consistent Hashing)及其在分布式系统中的应用。首先本文会描述一个在日常开发中经常会遇到的问题场景,借此介绍一致性哈希算法以及这个算法如何解决此问题;接下来会对这个算法进行相对详细的描述,并讨论一些如虚拟节点等与此算法应用相关的话题。 分布式缓存问题 假设我们有一个网站,最近发现随着流量增加,服务器压力越来越大转载 2015-08-17 20:47:49 · 633 阅读 · 0 评论 -
Dijkstra算法
#include #include using namespace std; #define MAXN 10002 int 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 · 371 阅读 · 0 评论 -
DFS的时间戳应用
#include using 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 · 1465 阅读 · 0 评论 -
BFS 数组模拟队(有向图)
#include using 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 · 731 阅读 · 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 · 460 阅读 · 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 · 625 阅读 · 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 · 507 阅读 · 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 · 651 阅读 · 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 · 583 阅读 · 0 评论 -
BFS 队 (有向图)
#include #include using 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 · 494 阅读 · 0 评论 -
欧拉图算法
首先考虑是欧拉图。若从一个顶点出发,利用DFS,将新搜索到的顶点保存到栈顶,并且将走过的边给删除,那么一定能访问到这个初始顶点。因为除起始顶点外其他的顶点若被访问到那么一定能去访问别的顶点。但是起始顶点不同,它是被直接访问的,即没有通过别的顶点去访问它,因此我们一定能找到这样的回路,使得起始顶点和终点是同一顶点,设为v,并且v的所有边都在这条回路上。我们用栈来保存这些顶点(按访问的顺序),如果此时原创 2015-04-20 15:25:19 · 2134 阅读 · 0 评论 -
求最长回文子串,O(n)复杂度
最长回文子串问题—Manacher算法 最长回文串问题是一个经典的算法题。 0. 问题定义 最长回文子串问题:给定一个字符串,求它的最长回文子串长度。 如果一个字符串正着读和反着读是一样的,那它就是回文串。下面是一些回文串的实例: 12321 a aba abba aaaa tattarrattat(牛津英语词典中最长的回文单词)原创 2016-04-04 13:25:09 · 4429 阅读 · 1 评论