网络流
文章平均质量分 78
yrleep
大学毕业不久,ios游戏自由开发者。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
poj 2699 The Maximum Number of Strong Kings 网络流
#include #include #include using namespace std; const int maxn=19; int a[maxn],e[70][70],flag[maxn]; int n; void makegraph() { memset(e,0,sizeof(e)); int ret=0; for(int i=1;i<=n;i++)原创 2013-10-27 16:37:30 · 857 阅读 · 0 评论 -
poj 1966 Cable TV Network
枚举源点和汇点。 #include #include #include using namespace std; const int maxn=109,inf=1e8; int n,m; int a[maxn][maxn]; int que[maxn],level[maxn]; int head[maxn],lon; struct { int next,to,c; }e[max原创 2013-11-02 00:23:37 · 1020 阅读 · 0 评论 -
poj 2396 Budget 有上下界的网络流
对上下界网络流的解法很多地方有,就不再叙述了,说说自己的理解,网络流的算法能解决分配的问题,而上下界网络流的不同在于下界必须流满,所以做法就是先用网络流算法把下界流满,然后转化成普通网络流算法解决。 #include #include #include using namespace std; const int maxn=2e2+9,inf=1e9,N=10000,M=1000; i原创 2013-10-23 23:11:55 · 828 阅读 · 0 评论 -
poj 1815 Friendship 网络流
求最小割就没什么可说的了。关键是怎么判断一条边能不能成为割边,如果能够成为割边,那么做完最大流之后,起点肯定不能达到终点,否则这条边容量减小对最大流没有影响。那么怎么去掉这条边呢?反向压一次流。 #include #include #include using namespace std; const int maxn=4e2+9,inf=1e7; int n,s,t; int d[m原创 2013-10-23 00:13:50 · 1001 阅读 · 0 评论 -
hdu 4494 Teamwork 网络流
网上比较多的代码都是用费用流做的,但是这个题目简单的描述就是求最小路径覆盖,每个点覆盖的次数不是1了而已。简单修改求最小路径覆盖的方法即可,源点向顶点,顶点向汇点连的边都变成点需要被覆盖的次数即可。 #include #include #include using namespace std; const int maxn=15e1+9,inf=1e9; int n,m; int su原创 2013-10-28 22:45:32 · 1108 阅读 · 0 评论 -
poj 2446 网络流
先黑白染色,然后每个覆盖必须覆盖一个黑点一个白点,那么就是一个二分图,一个覆盖就是一次匹配,那么就求一下最大匹配就好了。 #include #include #include using namespace std; const int maxn=1100,inf=1e9; int n,m,k; int flag[35][35]; int level[maxn],que[maxn];原创 2013-10-27 22:25:40 · 725 阅读 · 0 评论 -
poj 3281 网络流
经典题目,拆点网络流。 #include #include #include using namespace std; const int maxn=4e2+9,inf=1e9; int n,f,d; int level[maxn],que[maxn]; int head[maxn],lon; struct { int next,to,c; }e[maxn*maxn<<1];原创 2013-10-27 16:56:16 · 763 阅读 · 0 评论 -
poj 2391 Ombrophobic Bovines 网络流
二分答案+网络流判定,一定得拆点。 #include #include #include #include using namespace std; const int maxn=2e2+9,inf=1e9; long long d[maxn][maxn]; int n,m,sum; int level[maxn<<1],que[maxn<<1]; int head[maxn<<1],l原创 2013-10-27 16:29:08 · 771 阅读 · 0 评论 -
poj 3308 Paratroopers 网络流
由于最后结果是相乘,所以先log一下,转化成想加。 然后点做边,行,列做点。最小权覆盖。 #include #include #include #include using namespace std; const int maxn=2e2+9; const double inf=1e20,epx=1e-4; int que[maxn],level[maxn]; int head[原创 2013-10-27 21:45:44 · 777 阅读 · 0 评论 -
poj 1637 Sightseeing tour 网络流
经典题目,很多书上都有解答。 首先得用一个结论,一个联通的有向图存在欧拉回路当且仅当每个点的入度等于出度。 那么这个题目的做法就是先给无向边任意定向,然后源点向入度大于出度的点连边,出度大于入度的向汇点连边,网络流判断能不能使得最后每个点的入度都等于出度。 #include #include #include using namespace std; const int maxn=原创 2013-10-27 12:19:40 · 820 阅读 · 0 评论 -
poj 3680 Intervals 费用流
#include #include #include #include using namespace std; const int maxn=1e3+9,inf=1e8; int from[maxn],to[maxn],w[maxn],x[maxn]; int head[maxn],lon; int dist[maxn],inque[maxn],que[1111111]; int T,n原创 2013-10-20 23:42:46 · 1037 阅读 · 0 评论 -
poj 2112 网络流
题意:有K台挤奶机(编号1~K),C头奶牛(编号K+1~K+C),给出各点之间距离。现在要让C头奶牛到挤奶机去挤奶,每台挤奶机只能处理M头奶牛,求使所走路程最远的奶牛的路程最短的方案。 构图:先Floyd求所有点对之间最短路,二分最短长度,若奶牛与挤奶机之间的距离大于mid则不连边,否则连容量为1的边。源向奶牛连容量1的边,机器向汇连容量m的边,用最大流判可行性。 #include #incl原创 2013-04-14 19:37:42 · 551 阅读 · 0 评论 -
poj 3155 Hard Life 分数规划+最大权闭合图
这个就是完全按照论文中的做法来搞了,输出割边的时候就dfs判断一下在残余网络中该点是否可达汇点,不可达则是割边。 当然这么做还有一个前提就是最大全闭合图是唯一的,所以不会存在不同的割边集。 #include #include #include using namespace std; const int maxn=1e2+9,inf=1e9; const double epx=1e-原创 2013-10-25 23:54:27 · 972 阅读 · 0 评论 -
poj 2125 Destroying The Graph
最小点权覆盖加输出路径。 #include #include #include using namespace std; const int maxn=3e3+9,inf=2e9; int in[maxn],out[maxn]; int S,T,level[maxn],que[maxn]; bool visit[maxn]; int n,m; int head[maxn],lon; s原创 2013-10-26 21:06:17 · 769 阅读 · 0 评论 -
poj 3084 最小割
简单的求最小割 不知道为什么这么少人A #include #include #include #include using namespace std; const int maxn=30,inf=1e6; int n,m; int level[maxn],que[maxn]; int head[maxn],lon; struct { int next,to,c; }e[ma原创 2013-10-24 20:57:13 · 672 阅读 · 0 评论 -
poj 2987 Firing 最大权闭合图 网络流
最大权闭合的求法参看黑书 #include #include #include using namespace std; const int maxn=5e3+9,maxm=6e4+9; const long long inf=(long long)1<<50; int level[maxn],head[maxn],que[maxn]; int lon; struct { int原创 2013-06-03 13:32:36 · 953 阅读 · 0 评论 -
poj 3204 网络流
用dinic求最大流 然后枚举残余网络中,正边容量为0的边,容量加1,若能makelevel,ans++; #include #include #include using namespace std; const int inf=1<<30; const int maxn=1011; struct node { int to,w,next; }e[20001]; int hea原创 2013-04-14 19:37:50 · 627 阅读 · 0 评论 -
poj 2455 二分+网络流
题意: 保留图中的一些边,使得每条边只走一次的情况下,起点到终点至少有t条路径,求满足此要求的图中最长的边最短为多少? 二分答案,然后用网络流判断可行性。 #include #include #include using namespace std; const int inf=1 const int maxn=301; struct { int to原创 2013-04-14 19:37:46 · 580 阅读 · 0 评论 -
poj 1149 网络流
构图:源点向每个顾客连买猪数目的边,若顾客是第一个来到该猪圈的,则像猪圈连一条猪圈猪数目的边 ,否则像上一个来到该猪圈的顾客连一条inf的边,猪圈向汇点连接一条猪圈猪数目的边,最大流 用了dinic算法 #include #include #include using namespace std; const int inf=1 const int maxn=2001;原创 2013-04-14 19:37:48 · 430 阅读 · 0 评论 -
poj 1273
网络流 用了dinic #include #include #include const int maxn=1001; using namespace std; const int inf=1 struct { int to,f,next; }e[maxn]; int head[maxn],lon; int edgeini(int n) { for(int i=1;i l原创 2013-04-14 19:37:38 · 540 阅读 · 0 评论 -
poj 1698
网络流 #include #include #include using namespace std; const int inf=1 const int maxn=1001; int e[maxn][maxn]; int que[maxn],test[maxn],from[maxn]; int bfs(int s,int t,int n) { memset(test,0,siz原创 2013-04-14 19:37:36 · 495 阅读 · 0 评论
分享