USACO Section 4.2: The Perfect Stall
这题关键就在将题转换成最大流模板题。首先有一个原始点,N个cow个点, M个barn点和一个终点,原始点到cow点和barn点到终点的流都为1,而cow对应的barn就是cow点到对应barn点的流,为1.这样题目就转换成了原始点到终点的最大流问题
/* ID: yingzho1 LANG: C++ TASK: stall4 */ #include <iostream> #include <fstream> #include <string> #include <map> #include <vector> #include <set> #include <algorithm> #include <stdio.h> #include <queue> #include <cstring> #include <cmath> #include <list> #include <cstdio> #include <cstdlib> #include <limits> #include <stack> using namespace std; ifstream fin("stall4.in"); ofstream fout("stall4.out"); ; ; int N, M; *MAX][*MAX], f[*MAX][*MAX], pre[*MAX], inc[*MAX]; bool bfs(int s, int d) { queue<int> que; ; i <= N+M+; i++) pre[i] = -; que.push(s); inc[s] = INF; while (!que.empty()) { int u = que.front(); que.pop(); ; i <= N+M+; i++) { && f[u][i] < g[u][i]) { inc[i] = min(inc[u], g[u][i]-f[u][i]); pre[i] = u; if (i == d) return true; que.push(i); } } } return false; } int edmond_karp(int s, int d) { ; while (bfs(s, d)) { maxflow += inc[d]; for (int i = d; i != s; i = pre[i]) { f[pre[i]][i] += inc[d]; f[i][pre[i]] -= inc[d]; } } return maxflow; } int main() { fin >> N >> M; int s, d; ; i <= N; i++) { g[][+i] = ; fin >> s; ; j < s; j++) { fin >> d; g[+i][+N+d] = ; } } ; i <= N+M+; i++) g[i][N+M+] = ; fout << edmond_karp(, N+M+) << endl; ; }
USACO Section 4.2: The Perfect Stall的更多相关文章
- USACO Section 4.2 The Perfect Stall(二分图匹配)
二分图的最大匹配.我是用最大流求解.加个源点s和汇点t:s和每只cow.每个stall和t 连一条容量为1有向边,每只cow和stall(that the cow is willing to prod ...
- USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)
The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...
- usaco training 4.2.2 The Perfect Stall 最佳牛栏 题解
The Perfect Stall题解 Hal Burch Farmer John completed his new barn just last week, complete with all t ...
- POJ1274 The Perfect Stall[二分图最大匹配]
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
- poj 1247 The Perfect Stall 裸的二分匹配,但可以用最大流来水一下
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16396 Accepted: 750 ...
- POJ1274 The Perfect Stall
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25739 Accepted: 114 ...
- POJ1274 The Perfect Stall[二分图最大匹配 Hungary]【学习笔记】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- poj——1274 The Perfect Stall
poj——1274 The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25709 A ...
随机推荐
- android中 回调方法,怎么转变为阻塞执行的方法
项目中需要用到在wifi这一块,扫描附近wifi,然后一个个遍历所有wifi,并且尝试连接,所以就在这里需要每连接一个wifi进行阻塞,当连接失败的时候才进行尝试下一个连接,当连接成功时则break. ...
- 如何ping通两台计算机
如何ping通两台计算机 因为ping是基于IP协议的,所以,先要保证两台计算机在同一个子网中,这里涉及到vlan和子网的概念 若两台主机不在同一个子网中则无法ping通 若两台主机在同一个子网中却p ...
- 1565: [NOI2009]植物大战僵尸 - BZOJ
Description Input Output仅包含一个整数,表示可以获得的最大能源收入.注意,你也可以选择不进行任何攻击,这样能源收入为0.Sample Input3 210 020 0-10 0 ...
- SimpleDateFormat
范例: Date date = new Date();SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MMM-dd,E,HH. ...
- Least Common Ancestors 分类: ACM TYPE 2014-10-19 11:24 84人阅读 评论(0) 收藏
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> #i ...
- Oracle NULL 和空值
如果你工作中用到了Oracle,你必须要留意NULL和空值的处理与SQL Server上的不同.现在让我们看些例子. 建立这张数据库表并插入记录 CREATE TABLE TestNull(Col ...
- 利用PE数据目录的导入表获取函数名及其地址
PE文件是以64字节的DOS文件头开始的(IMAGE_DOS_HEADER),接着是一段小DOS程序,然后是248字节的 NT文件头(IMAGE_NT_HEADERS),NT的文件头位置由IMAGE_ ...
- Codeforces Round #FF (Div. 2)
又一场中国场,果然注定被虐的场... A,B:都很水,差不多模拟就好了: C题:CF难得的题意简洁, 我们可以预处理出从左到右递增的数列个数, 举个例子:1 3 2 4 5 7 L[I] ...
- Codeforces Round #254DIV2
C:万恶的一道题: 开始想用贪心做:每次去除一个点,相应的去除相连边,结果BUG了,想想也对,因为有一次去掉多个点的情况, 后来被送一助攻,队友给出一个猜想:可能枚举一条边即可产生最大值:然后小小证明 ...
- 定时器 corn 表达式
一个cron表达式有至少6个(也可能7个)有空格分隔的时间元素.按顺序依次为1.秒(0~59)2.分钟(0~59)3.小时(0~23)4.天(月)(0~31,但是你需要考虑你月的天数)5.月(0~11 ...