随笔分类 - flow
摘要:题意:给出n栋房子位置和每栋房子里面的人数,m个避难所位置和每个避难所可容纳人数。然后给出一个方案,判断该方案是否最优,如果不是求出一个更优的方案。思路:很容易想到用最小费用流求出最优时间,在与原方案花费时间对比判断原方案是否最优。但是这种方法会超时的。 放弃该思路。看看题目没要求要最优解,而是得到一个更优的解,那么如果在原图中能够找到一个总费用为负的回路的话,那就该解不是最优解,把该负环消去,更新流量,得到优化后的解。具体操作:在SPFA中,一个点入队次数大于顶点数时就可以判断有负圈存在了,但这时刚刚入队的这个点却未必是负圈上的,如数据1 30 0 41 0 61 1 61 2 60 2 2
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 110#define maxm 6000#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, next, c, w;}edge[maxm<<2];int head[maxn], tot;in
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 100300#define maxm 200003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, c, w, next;}edge[maxm<<3];int head[maxn], t
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 5010#define maxm 10030#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, c, w, next;}edge[maxm<<3];int head[maxn], tot;
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define maxn 1010#define maxm 10003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int u, v, c, w, next;}edge[maxm<<3];int head[maxn], tot;
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#define maxn 504#define maxm 100003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}int max(int a, int b){ return a > b ? a : b;}struct E{ int v, next, c;}edge[maxm];int head[maxn], tot;int n, m;int S, T;int s, t;void i
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 410#define maxm 40003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[maxm];int head[maxn], tot;int n, m;int S, T;void add(int s, int
阅读全文
摘要:每条边的容量满足一定的限制,即有一个上限值,也有一个下限值上界用ci表示,下界用bi表示。下界是必须流满的,那么对于每一条边,去掉下界后,其自由流为ci– bi。主要思想:每一个点流进来的流=流出去的流对于每一个点i,令Mi= sum(i点所有流进来的下界流)– sum(i点所有流出去的下界流)如果Mi大于0,代表此点必须还要流出去Mi的自由流,那么我们从源点连一条Mi的边到该点。如果Mi小于0,代表此点必须还要流进来Mi的自由流,那么我们从该点连一条Mi的边到汇点。如果求S->T的最大流,看是否满流(S的相邻边都流满)。满流则有解,否则无解。View Code #include<
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 803#define maxm 10003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[maxm<<2];int head[maxn], tot;int n, m, s, t;void add(int
阅读全文
摘要:View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 410#define maxm 40003#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[maxm];int head[maxn], tot;int n, m;void add(int s, int t, int c
阅读全文
摘要:View Code #include<stdio.h> #include<string.h> const int maxn = 20100; const int maxm = 200200; const int inf = 1<<29; struct node { int v, c, next; }edge[maxm*6]; int head[maxn], tot; int n, m; void init() { int i; for(i = 0; i <= n+2; i++) head[i] = -1; tot = 0; } voi...
阅读全文
摘要:1062* 昂贵的聘礼 枚举等级限制+dijkstra1087* A Plug for UNIX 2分匹配1094 Sorting It All Out floyd 或 拓扑1112* Team Them Up! 2分图染色+DP1122 FDNY to the Rescue! 最短路1125 Stockbroker Grapevine FLOYD1128 Frame Stacking 拓扑排序1135 Domino Effect 最短路 1149* PIGS 网络流1161* Walls Floyd1192 最优连通子集1201 Intervals 差分约束1236* Network of
阅读全文
摘要:为什么要拆点:2 410 0 0 0 110 0 0 0 010 0 1 1 110 0 1 1 1拆点10, 不拆点20做最大流的题目无非是这两步。1.建图2.套sap+gap优化的模板View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 106#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, n
阅读全文
摘要:本题关键是建图,然后SAP水一个建图:设0为源点,1为汇点,所以检索表里的插头下标要从2开始。先输入n个插座,每个插座与汇点相连,值为1。再输入m个用电器,用电器的名称其实是个无用的信息,把每个用电器的插头与源点相连,值为1。然后输入k个转换器,如B X,则B与X连,注意值为INF(无穷大),因为这种类型的转换器可以有无数个。最后SAP水一个,水题鉴定完毕。View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define INF 100000
阅读全文
摘要:sap模板题,输入比较麻烦,漏了个分号检查了半天View Code #include<stdio.h>#include<string.h>#include<algorithm>#define maxn 105#define INF 100000000using namespace std;int c[maxn][maxn],dis[maxn],num[maxn];int pre[maxn];int s, t, vs;int n, m, np,nc;void sap(){ memset(dis,0,sizeof(dis)); memset(num,0,size
阅读全文
摘要:dinic1719MSView Code #include<stdio.h>#include<string.h>#include<algorithm>#include<queue>using namespace std;#define INF 1000000#define maxn 250int dis[maxn][maxn];int c[maxn][maxn];bool vis[maxn];bool sign[maxn][maxn];int K,C,M;int s, t, n;void floyd(){ int i, j, k; for(k=1
阅读全文
摘要:sap+gap优化View Code #include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define maxn 105#define inf 1000000000int min(int a, int b){ return a < b ? a : b;}struct E{ int v, next, c;}edge[10003 << 1];int head[maxn], tot;int n, m;void add(int s, int t, in
阅读全文

浙公网安备 33010602011771号