随笔分类 - 算法模版
摘要:http://www.cnblogs.com/looker_acm/archive/2010/08/15/1799919.html/*** 混合图欧拉回路** 只记录各定点的出度与入度之差,有向边无用丢弃,将无向边定向,在网络中建立流量为1的边** 另新建s和t。对于入 > 出的点u,连接边(u, t)、容量为x,对于出 > 入的点v,连接边(s, v),** 容量为x(注意对不同的点x不同)。之后,察看是否有满流的分配,如果是满流则存在,否则不存在*/#include #include #include #include #include using namespace std;
阅读全文
摘要:#include #include #include #include #include using namespace std;const int maxn = 16100;struct node { int v,next;} edge[41000];int head[maxn],sta[maxn],vis[maxn];int id,top,n;void add_edge(int u,int v){ edge[id].v = v;edge[id].next = head[u];head[u] = id++;}int dfs(int u){ if( vis[u^1] )r...
阅读全文
摘要:#include#include#include#include#include#includeusing namespace std;int const oo = 100000000;int cost[103][103]; // 花费=边 int used[103][103]; // 表示这条边是否在生成树中 int father[103]; // 生成树中点的 int maxlen[103]; // 表示i点到根的路径上除了与根直接相连的边外,边权最大的边的边权。int vis[103]; // 标记 int d[103]; // 求最...
阅读全文
摘要:=============== 分割线之下摘自Sasuke_SCUT的blog=============最 小树形图,就是给有向带权图中指定一个特殊的点root,求一棵以root为根的有向生成树T,并且T中所有边的总权值最小。最小树形图的第一个算法是 1965年朱永津和刘振宏提出的复杂度为O(VE)的算法。 判断是否存在树形图的方法很简单,只需要以v为根作一次图的遍历就可以了,所以下面的 算法中不再考虑树形图不存在的情况。 在所有操作开始之前,我们需要把图中所有的自环全都清除。很明显,自环是不可能在任何一个树形图上的。只有进 行了这步操作,总算法复杂度才真正能保证是O(VE)。 首先为除根之外
阅读全文
摘要:http://blog.csdn.net/niushuai666/article/details/7002823#include #include #include using namespace std;struct node{ int count; node *next[26],*fail; void Node(){ count = 0;fail = NULL; memset(next,NULL,sizeof(next)); }}arr[300005],*que[500005];char str[1000006];int cnt = 0;...
阅读全文
摘要:题意: 莱克尔和她的朋友到公园玩,公园很大也很漂亮。公园包含n个景点通过n-1条边相连。克莱尔太累了,所以不能去参观所有点景点。经过深思熟虑,她决定只访问其中的k个景点。她拿出地图发现所有景点的入口都很特殊。所以她想选择一个入口,并找到一条最短的路来参观k个景点。我们假设景点之间的距离为1。解题思路:因为地图形状为树形,所以求树的最大直径。当k小于等于直径的时候输出k-1,当k大于直径的时候,因为访问了某一个景需要返回直径所在的路径上,所以当k大于冷的时候结果为len-(k-len-1)*2。#include #include #include #include #include using
阅读全文
摘要:简单排列组合题,输入n,m求n中选m个数的种类#include__int64 work(__int64 n,__int64 k){//求在n个数中选m个数的组合数. __int64 i,sum,j = 1; if(k > n) return 0; //求组合数 for(sum = 1,i = k; i ; i--) { sum *= n--; while(sum%j == 0 && j n) m = n-m; printf("%I64d\n",work(n,m)); } return 0;}
阅读全文
摘要:最近又复习了下最大流问题,每次看这部分的内容都会有新的收获。可以说最大流问题的资料网上一搜一大把,根本没有必要自己写;但是大部分资料上的专业术语太多了,初学很难理解,至少我当年学这部分的时候前几次就没有看懂。所以我准备备份一点个人的理解。图-1如图-1所示,在这个运输网络中,源点S和汇点T分别是1,7,各边的容量为C(u,v)。图中红色虚线所示就是一个可行流。标准图示法如图-2所示: 其中p(u,v) / c(u,v)分别表示该边的实际流量与最大容量。关于最大流熟悉了什么是网络流,最大流也就很好理解了。就是对于任意的u∈V-{s},使得p(s,u)的和达到最大。上面的运输网络中,最大流如图-3
阅读全文
摘要:#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define LL long long#define pii pair#define bug coutr) return ; int m=(r+l)>>1; newNode(x,m); makeTree(ch[...
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2544简单最短路问题#include#define INF 1 dis[i] + map[i][j]) dis[j] = dis[i] + map[i][j]; } } } for(i = 1; i dis[i] + map[i][j]) return false; } return true;}int main(){ int i,j,a,b,c; ...
阅读全文
摘要:一个人的旅行Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10311 Accepted Submission(s): 3500Problem Description虽然草儿是个路痴(就是在杭电待了一年多,居然还会在校园里迷路的人,汗~),但是草儿仍然很喜欢旅行,因为在旅途中 会遇见很多人(白马王子,^0^),很多事,还能丰富自己的阅历,还可以看美丽的风景……草儿想去很多地方,她想要去东京铁塔看夜景,去威尼斯看电影,去阳明山上看海芋,去纽约纯
阅读全文
摘要:题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=2680简单最短路问题。。。。。运行结果:Accepted2680265MS4164K1382 BC++//dijkstra#include#define INF (1 min + map[k][j]) dis[j] = min + map[k][j]; } }}int main(){ int i,j,start,end,cost,w; while(scanf("%d%d%d",&n,&m,&s) != EOF) { for(i = 0; i cost) m
阅读全文

浙公网安备 33010602011771号