摘要:求最大流后判断下那些边的容量为0即可。。View Code #include<stdio.h>#include<stdlib.h>#include<string.h>#include<iostream>#include<vector>#include<string>#include<math.h>#include<map>#include<set>#include<algorithm>using namespace std;#define MAXN 2000000struct
阅读全文
摘要:1.sap递归版。View Code #include <iostream>using namespace std;#define MAXN 10000struct Edge{ int v, next, val; Edge( ) { } Edge( int V, int N, int Val): v(V), next(N), val(Val) {} }edge[MAXN];int head[MAXN],size, flow, visit, sum, N, M, ans;int gap[MAXN], h[MAXN];/*sap算法核心:1.dfs搜索增广路2.标号 ...
阅读全文
摘要:刚开始我是则这样构图的1.源点到1-7天的天数为最大的周数2.每天与其对应的演电影的时间连接,容量为其周数3.把每部电源的所有演出时间点再汇聚到一个节点(容量为inf),再把这个节点与汇点连边,容量为该部电源其所需天数。这样构图,一直wa, 早上起来才想到,没有考虑时间先后顺序。如这组测试数据331 1 1 1 1 1 1 105 151 1 1 1 1 1 1 14 21 1 1 1 1 1 1 7 20正确的构图应该这样, 把所有时间(那天可以演电影的对应一个点,最后得到一个时间的点集。20 1 0 1 0 1 0 9 31.构造时间的点集合为point = { day{ (week -
阅读全文
摘要:Sample Input14 5 21 1233 24 2441 42 3结合输入数据讲题意,1,就是一组输入数据,4表示有2 * 4个人,女生编号为1-4, 男生编号也为1-4,5表示下面接下来5对关系是没有吵过架的,2表示为有2对女生女生是好朋友的关系,也就是最后输入的那两行题目是要我们求每个女生找一个男生,并且这个男生没有和她吵过架,如果她朋友没有跟这个男生吵过架也可以。还有就是女生之间的朋友关系可以传递。但是不能找以前她已经找过的男生。。当每个女生找到一个男生后,这个游戏就算玩了一次,然后接着继续玩。要我们解决的问题是,这个游戏最多可以玩几圈。算法:1.并查集因为女生之间的朋友关系可以
阅读全文
摘要:1. Edmonds-karp 算法用广度优先搜索来实现对增广路径p的计算,即如果增广入径是残留网络中从(s到t的最短路径,就能改进FORD-FULKERSON的界,称Ford-Fulkerson方法的这种实现为Edmonds-karp算法,时间复杂度为O(VE^2);HDU 3549View Code #include <stdio.h>#include <string.h>#include <stdlib.h>#include <deque>using namespace std;int cap[100][100];int a[100];in
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <deque>#include <algorithm>using namespace std;int cap[1000][1000];int flow[1000][1000];int a[1000];int f;int p[1000];const int inf = 0x7fffffff;void Edmonds_karp(int N, int M ){ deque<int>q; int t,
阅读全文
摘要:#include <stdio.h>#include <string.h>#include <stdlib.h>#include <deque>using namespace std;int cap[100][100];int a[100];int flow[100][100];int path[1010];int N,M;const int inf = 0x7f7f7f7f;int f;void BFS( ){ int i, j, k, t, u, v; f = 0; memset(flow, 0, sizeof(flow)); for (;
阅读全文