poj-1807(最大流)】的更多相关文章

很巧妙的思想 转自:http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html 本题能够想到用最大流做,那真的是太绝了.建模的方法很妙! 题意就是有N头牛,F个食物,D个饮料. N头牛每头牛有一定的喜好,只喜欢几个食物和饮料. 每个食物和饮料只能给一头牛.一头牛只能得到一个食物和饮料. 而且一头牛必须同时获得一个食物和一个饮料才能满足.问至多有多少头牛可以获得满足. 最初相当的是二分匹配.但是明显不行,因为要分配两个东西,两个东…
找了好久这两个的区别...UVA820 WA了 好多次.不过以后就做模板了,可以求任意两点之间的最大流. UVA 是无向图,因此可能有重边,POJ 1273是有向图,而且是单源点求最大流,因此改模板的时候注意一下. 而且我居然犯了更愚蠢的错误,以为重边的时候需要选最大的,正解应该是累加.... #include<stdio.h> #include<queue> #include<string.h> #define INF 999999 using namespace s…
题目链接:http://poj.org/problem?id=1273 a.EK算法:(Edmond-Karp): 用BFS不断找增广路径,当找不到增广路径时当前流量即为最大流. b.dinic算法:不断找最短路. 题意:现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的池塘和所能流过的水量,求水渠中所能流过的水的最大容量. //http://blog.csdn.net/huzhengnan/article/details/7766446一个写的特别好的博…
题目链接:http://poj.org/problem?id=1149 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn 1050 #define maxe 200000 using nam…
题目链接:http://poj.org/problem?id=3281 #include <cstdio> #include <cmath> #include <algorithm> #include <iostream> #include <cstring> #include <queue> #include <vector> #define maxn 105 #define maxe 20000 using names…
Alice's Chance Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7327   Accepted: 2992 Description Alice, a charming girl, have been dreaming of being a movie star for long. Her chances will come now, for several filmmaking companies invit…
转载 百度文库花了5分下的 不过确实是自己需要的东西经典的最大流题POJ1273 ——其他练习题 POJ3436 . 题意描述: 现在有m个池塘(从1到m开始编号,1为源点,m为汇点),及n条水渠,给出这n条水渠所连接的池塘和所能流过的水量,求水渠中所能流过的水的最大容量.一道基础的最大流题目.但是模板小心使用,目前只是求单源点的最大流. 参考数据: 输入: 5 4 1 2 40 1 4 20 2 4 20 2 3 30 3 4 10 输出: 50 程序实现: 增广路算法Edmonds_Karp…
题意:有N个供应商,M个店主,K种物品.每个供应商对每种物品的的供应量已知,每个店主对每种物品的需求量的已知,从不同的供应商运送不同的货物到不同的店主手上需要不同的花费,又已知从供应商m送第k种货物的单位数量到店主n手上所需的单位花费.供应是否满足需求?如果满足,最小运费是多少? 思路:这题一读完就知道是费用流了,刚开始想着拆点,不过算了一下,把m个供应商拆成m*k个点,n个店主拆成n*k个点,加起来有5000多个点,肯定会超时的,看了网上说每种商品求一次费用流就可以了,就是100个点求50次.…
最大流简单题,,这题重要的是知道了scanf("%s",str);sscanf(str,"(%d,%d)%d",&x,&y,&w);读入方式 #include<stdio.h> #include<string.h> const int N=210; const int inf=0x3fffffff; int dis[N],gap[N],head[N],num,start,end,ans,n,m; struct edge…
Paratroopers Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 3308 Appoint description:  System Crawler  (2014-10-14) Description It is year 2500 A.D. and there is a terrible war between the forc…
题意抽象出来就是给了一个费用流的残存网络,判断该方案是不是最优方案,如果不是,还要求给出一个更优方案. 在给定残存网络上检查是否存在负环即可判断是否最优. 沿负环增广一轮即可得到更优方案. 考虑到制作模板的需要,我用前向星建图做的.此题用邻接矩阵应该更方便. #include<queue> #include<cstdio> #include<algorithm> #include<cstring> #define rep(i,a,b) for(int i=a…
On a grid map there are n little men and n houses. In each unit time, every little man can move one unit step, either horizontally, or vertically, to an adjacent point. For each little man, you need to pay a $1 travel fee for every step he moves, unt…
Jamie's Contact Groups Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 7624   Accepted: 2562 Description Jamie is a very popular girl and has quite a lot of friends, so she always keeps a very long contact list in her cell phone. The con…
March of the Penguins Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 4809   Accepted: 2195 Description Somewhere near the south pole, a number of penguins are standing on a number of ice floes. Being social animals, the penguins would l…
Dining Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17251   Accepted: 7643 Description Cows are such finicky eaters. Each cow has a preference for certain foods and drinks, and she will consume no others. Farmer John has cooked fabulo…
题目链接:http://poj.org/problem?id=3498 思路:首先设一个超级源点,将源点与各地相连,边容量为各点目前的企鹅数量,然后就是对每个冰块i进行拆点了(i,i+n),边容量为能够接受的受损程度,这样就把点权问题转化为边权问题了,然后就是对于那些能够相互跳跃的冰块之间连边(i+n,j),(j+n,i),边容量为inf.最后就是枚举汇点看是否等于总数. #include<iostream> #include<cstdio> #include<cstring…
题目链接:http://poj.org/problem?id=3281 看了kuangbin大佬的思路,还用着kuangbin板子orz   http://www.cnblogs.com/kuangbin/archive/2012/08/21/2649850.html #include<cstdio> #include<cstring> using namespace std; ; ; const int INF = 0x3f3f3f3f; struct Edge { int to…
题目链接:http://poj.org/problem?id=3436 大力套kuangbin板过了orz #include<cstdio> #include<cstring> using namespace std; ; ; const int INF = 0x3f3f3f3f; struct Edge { int to,next,cap,flow; } edge[MAXM]; int tol; int head[MAXN]; int gap[MAXN],dep[MAXN],pr…
  Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24788   Accepted: 12922 Description A power network consists of nodes (power stations, consumers and dispatchers) connected by power transport lines. A node u may be supplied with an amou…
题目链接:http://poj.org/problem?id=2391 今天掉坑多次. 做了几道题,发现从源点出来的边和进入汇点的边都在题目中出来过. POJ真是坑,交G++一直wa,检查代码检查了好几遍,无望看discuss,才知道交C++是RE,才知道数组越界了. 手写了Floyd,写成 i,j,k,wa了,突然想到以前遇到过这种问题. 看昂神解释明白了. #include <cstdio> #include <cstring> #include <algorithm&g…
#include<stdio.h> #include<string.h> #define N 300 #define inf 0x7fffffff #include<queue> using namespace std; struct node {   int u,v,w,next; }bian[N*4]; int head[N],yong,d[N],s,t; void addedge(int u,int v,int w) {    bian[yong].u=u;  …
http://poj.org/problem?id=1459 也是网络流的基础,只是虚拟出一个源点和终点,对应的生产值和消费值就加到与源点和终点的边上,然后做一次bfs就好了. #include <iostream> #include <cstdio> #include <queue> #include <algorithm> #define INF 999999999 //#define OPEN_FILE using namespace std; ; i…
A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 15597   Accepted: 5308 Description You are in charge of setting up the press room for the inaugural meeting of the United Nations Internet eXecutive (UNIX), which has an int…
题目大意: 有 k台挤奶机 和 c头奶牛 每台挤奶机最多为m头奶牛服务 给定所有挤奶机和奶牛两两之间的距离 求一种分配 使得 奶牛与挤奶机之间的最远距离 最小化 floyd求得所有挤奶机与奶牛两两之间的最短距离 二分一个最远距离M 建图 超级源点s与所有奶牛连容量为1的边 所有挤奶机与超级汇点t连容量为m的边 奶牛与挤奶机之间距离<=M的连容量为1的边 跑s到t的最大流 若最大流为c 说明这个最远距离M是符合要求的 #include<iostream> #include<cstdi…
题目大意: N个模块 在核A上执行花费a[i] 在核B上执行花费b[i] 有M个模块组合(d1,d2) 若d1模块与d2模块在不同核上执行需多花费w[i] 求执行所有模块所需的最小花费 挑战P237 将问题转化为最小割问题 求得的最小割就是最小花费 那么记在核A上执行的模块集合为S 核B上执行的模块集合为T 建立源点s 汇点t 某模块在A上执行花费a[i] 则建一条该模块到t容量为a[i]的边 某模块在B上执行花费b[i] 则建一条s到该模块容量为b[i]的边 d1模块与d2模块在不同核上执行需…
A - PIGS POJ - 1149 这个题目我开始感觉很难,然后去看了一份题解,写的很好 https://wenku.baidu.com/view/0ad00abec77da26925c5b01c.html 这个总结了很多东西,可以去看看学习学习. 从这个题目可以学到的是先建出一个正确但是可能效率很低的模型出来,然后再去减少节点数量, 最后就可以解决这个题目了,这个说起来还挺简单的,但是并不是那么好做. #include <cstdio> #include <cstring>…
明天再拍一遍 #include <iostream> #include <queue> using namespace std; ; const int INF = 0x7FFFFFFF; int n,m,map[N][N],path[N],flow[N],start,end; queue<int> q; int bfs() { int i,t; while(!q.empty()) q.pop(); memset(path,-,sizeof(path)); path[s…
没啥好说的,慢慢建图 Sample Input 4 A B C D 5 laptop B phone C pager B clock B comb X 3 B X X A X D Sample Output 1 题意:有n个不同的插座,有m台不同的机器需要m种插头,有k组转换:插头A能由插头B转换而来.问这些机器最少有几台不能插上插座. #include<cstdio> #include<iostream> #include<algorithm> #include<…
从左上角到有下角k次能获得的最大值. 跟hdu 2686一样的题目,这题一个点可以重复走,只能得到一次值. #include<stdio.h> #include<string.h> #include<queue> const int N=5100; const int inf=0x3fffffff; using namespace std; int dist[N],head[N],num,start,end,n,vis[N],pre[N]; struct edge {…
题意:每台电脑共有p种零件,现在有n台机器,给出n台机器每台需要的一些种类零件当原料(0代表不需要,1代表必须要,2代表可有可无)和输出的产品零件.问怎么安排生产线使生产出来零件可以组装的电脑最多. 思路:如果机器的原材料什么都不需要的话就可以当源点,如果机器输出的零件种类为p就可以当汇点.刚开始想复杂了(1 0 1 可以同时跟1 0 0和0 0 1相连),这题只有当一台机器的输出格式跟另一台的输入格式一样时才可以相连,不能有多余的零件产生.最后想想如果不是这样的话,2代表的可有可无就没意义了.…