LouZhang

导航

2012年8月19日

hdu_2767,加边至强连通

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2767今天在做图论专题的时候碰到了这题,这样的话,正好学习了来写篇博客吧题目意思就是,给你一个有向网络图,问,至少加多少条边能使这个图成强连通那么就是要,先把图跑一遍targan,如果这个图是强连通,那么就输出0了,否则缩点,然后求所有点入度为0和出度为0个数的最大值了主要理解的地方就是缩点的那个地方,要理解belong数组的含义,以及为什么是求入度0和出席0的最大值证明我是不知道= =,真的是只能意会么 ?#include<cstdio>#include<cstring>#inclu 阅读全文

posted @ 2012-08-19 12:40 louzhang_swk 阅读(774) 评论(0) 推荐(0) 编辑

2012年8月17日

网络流sap需要注意的地方

摘要: int sap(){ memset(level, 0, sizeof level); memset(gap, 0, sizeof gap); memset(cur, 0, sizeof cur); int u = pre[s] = s; int aug = inf; gap[s] = n;这个要使源点gap值为点个数 int v; int flow = 0; while(level[s] < n){ for(v = cur[u]; v < n; v ++){ if(c[u][v] > 0 && level... 阅读全文

posted @ 2012-08-17 15:50 louzhang_swk 阅读(256) 评论(0) 推荐(0) 编辑

2012年8月12日

hdu_1269, 强连通分量的学习

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=1269#include<cstdio>#include<cstring>const int maxn = 10000 + 10;struct Edge{ int to, next;}e[maxn*10];int head[maxn], index;int dfn[maxn], low[maxn];int belong[maxn], vis[maxn];int step, color;void add_edge(int u, int v){ e[index].to = v, e[inde 阅读全文

posted @ 2012-08-12 21:25 louzhang_swk 阅读(227) 评论(0) 推荐(0) 编辑

hdu_2063,二分图最大匹配的学习

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=2063也拿这个当模板吧。。。#include<cstdio>#include<cstring>int k, m, n;bool g[510][510];int visit[510], link[510];bool dfs(int u){ for(int i = 1; i <= n; i ++){ if(g[u][i] && !visit[i]){ visit[i] = 1; if(link[i] == -1 || dfs(link[i])){ ... 阅读全文

posted @ 2012-08-12 16:34 louzhang_swk 阅读(155) 评论(0) 推荐(0) 编辑

poj_2516,最小费用最大流

摘要: http://poj.org/problem?id=2516参考这篇博客写的。。。http://www.cppblog.com/Icyflame/archive/2009/06/30/88941.html这几天算是被网络流整死了,算法太复杂了,理解起来确实是难。。2516#include<cstdio>#include<cstring>const int inf = 10000000;const int maxn = 110;struct Edge{ int u, v, w, c, next;}e[maxn * maxn * 4];int head[maxn], ind 阅读全文

posted @ 2012-08-12 14:00 louzhang_swk 阅读(212) 评论(0) 推荐(0) 编辑

2012年8月11日

poj_1459,sap的三种写法

摘要: 第一种是BFS的SAPbfs+sap#include<cstdio>#include<cstring>using namespace std;const int inf = 100000000;//不要开太大int n, np, nc, m;const int maxn = 105;int c[maxn][maxn];//残留网络int s, t;int level[maxn], gap[maxn];//层次网络, 层结点数(用于间隙优化)int q[maxn], pre[maxn];//队列, 前驱void init_sap(){ memset(level, 10, 阅读全文

posted @ 2012-08-11 17:20 louzhang_swk 阅读(287) 评论(0) 推荐(0) 编辑

2012年8月8日

欧拉路径问题

摘要: 我这个只是模板啦。。。用的fleury算法。。。当然也可以DFS求路径。。。原理感觉一样,只不过这更高效吧。。#include<cstdio>#include<cstring>int n,m;int e[100][100];int top;int stack[100];void dfs(int x){ top ++; stack[top] = x; for(int i = 1; i <= n; i ++){ if(e[x][i] > 0){ e[i][x] = e[x][i] = 0;//删除此边 dfs(i); ... 阅读全文

posted @ 2012-08-08 15:31 louzhang_swk 阅读(709) 评论(0) 推荐(1) 编辑

2012年8月3日

hdu_1166,树状数组的学习

摘要: 至于数状数组是怎么来的,这个得找资料了。。。也不知道怎么上传。。所以我也不讲了可以参考这个http://blog.csdn.net/cambridgeacm/article/details/7771782http://acm.hdu.edu.cn/showproblem.php?pid=1166这题是很经典的题,最开始是学线段树的时候做的,这次学树状数组,又做了一遍#include<cstdio>#include<cstring>const int maxn = 50000 + 10;int a[maxn], c[maxn];int n;inline int lowbi 阅读全文

posted @ 2012-08-03 12:26 louzhang_swk 阅读(186) 评论(0) 推荐(0) 编辑

2012年8月2日

hdu_4334,线性查找的学习

摘要: http://acm.hdu.edu.cn/showproblem.php?pid=4334这题开始做的时候,不是O(n^2)*O(logn^3) MLE就是O(n^3)*O(logn^2) TLE了后来看解题报告都没看懂幽幽子大神给我讲了下,真的是恍然大悟啊while(j < cnt1 && k >= 0){ if(f[j] + g[k] == -tmp){ flag = 1; break; } if(f[j] + g[k] < 0 - tmp) j ++; else k --;}对于这一段,开始用最小的加最大的,如果和小于要查找的... 阅读全文

posted @ 2012-08-02 19:42 louzhang_swk 阅读(556) 评论(0) 推荐(0) 编辑

poj1679,次小生成树的学习

摘要: 昨天总结MST的模板,也写的差不多了吧总之两种方法,kruskal和prim麻烦的可能就是生成MST的唯一性的判定原理很简单,先找MST,然后枚举MST上每条边,方法是删除该边再找MST,如果能找到MST并且权值等于第一次找到的,就不唯一了http://poj.org/problem?id=1679# include <iostream># include <cstdio># include <algorithm># include <cstring>using namespace std;//先求出最小生成树,然后删除这棵树上的每条边求MST, 阅读全文

posted @ 2012-08-02 10:08 louzhang_swk 阅读(177) 评论(0) 推荐(0) 编辑