网络流入门题目 - bzoj 1001
Sample Output14
Output
输出一个整数,表示参与伏击的狼的最小数量.
Sample Input
using namespace std;
#define ll long long
const int maxn = 1e6+5;
const int mod = 1e9+7;
const double eps = 1e-9;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f; int read() { //输入挂
int x = 0, f = 1; register char ch = getchar();
while (ch<'0' || ch>'9') { if (ch == '-')f = -1; ch = getchar(); }
while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); }
return x*f;
} int n, m;
struct node
{
int to, flow, next;
}edge[6*maxn];
int head[maxn];
int cnt = 0; void addedge(int u, int v, int w){
edge[cnt].next = head[u], edge[cnt].to = v, edge[cnt].flow = w, head[u] = cnt++;
edge[cnt].next = head[v], edge[cnt].to = u, edge[cnt].flow = w, head[v] = cnt++;
} int deep[maxn], que[maxn];
bool bfs(int s, int t){
int head1 = 0, tail1 = 1;
memset(deep, 0, sizeof(deep));
que[0] = s; deep[s] = 1; while(head1 < tail1){
int u = que[head1++];
for(int i = head[u]; i != -1; i = edge[i].next){
int v = edge[i].to;
if (!deep[v] && edge[i].flow) {
deep[v] = deep[u]+1;
que[tail1++] = v;
}
}
}
return deep[t];
} int dfs(int u, int f1){
if (u == n*m || f1 == 0) return f1; // !!!!! int f = 0;
for(int i = head[u]; i != -1; i = edge[i].next){
int v = edge[i].to;
if (edge[i].flow && deep[v] == deep[u]+1){
int x = dfs(v, min(f1, edge[i].flow));
edge[i].flow -= x; edge[i^1].flow += x;
f1 -= x, f += x;
if (f1 == 0) return f;
}
}
if (!f) deep[u] = -2;
return f;
} void solve() { int res = 0;
while(bfs(1, n*m)) {
res += dfs(1, inf);
}
cout << res << endl;
} int main() {
n = read(), m = read(); int i = 1, j = 2;
int x;
memset(head, -1, sizeof(head));
for(int k = 1; k <= n*m; k++){
if (i%m == 0) {i++, j++; continue;}
x = read();
addedge(i, j, x);
i++, j++;
}
i = 1, j = 1+m;
for(int k = 1; k <= (n-1)*m; k++){
x = read();
addedge(i, j, x);
i++, j++;
}
i = 1, j = 2+m;
for(int k = 1; k <= (n-1)*m; k++){
if (i%m == 0) {i++, j++; continue;}
x = read();
addedge(i, j, x);
i++, j++;
}
solve();
return 0;
}
网络流入门题目 - bzoj 1001的更多相关文章
- BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)
题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...
- nyoj_323:Drainage Ditches(网络流入门)
题目链接 网络流入门@_@,此处本人用的刘汝佳的Dinic模板 #include<bits/stdc++.h> using namespace std; const int INF = 0 ...
- 网络流入门-POJ1459PowerNetwork-Dinic模板
(我有什么错误或者你有什么意见,欢迎留言或私聊!谢谢!) (Ps:以前听说过网络流,想着以后再学,这次中南多校赛也碰到有关网络流的题目,想着这两天试着学学这个吧~~ 这是本人网络流入门第二题,不知道怎 ...
- Tile Cut~网络流入门题
Description When Frodo, Sam, Merry, and Pippin are at the Green Dragon Inn drinking ale, they like t ...
- 草地排水 洛谷P2740 最大流 入门题目
草地排水 洛谷P2740 最大流入门题目 题意 在农夫约翰的农场上,每逢下雨,贝茜最喜欢的三叶草地就积聚了一潭水.这意味着草地被水淹没了,并且小草要继续生长还要花相当长一段时间.因此,农夫约翰修建了一 ...
- s - t 平面图最大流 (附例题 bzoj 1001)
以下均移自 周冬的<两极相通-浅析最大最小定理在信息学竞赛中的应用> 平面图性质 1.(欧拉公式)如果一个连通的平面图有n个点,m条边和f个面,那么f=m-n+2 2.每个平面图G都有一个 ...
- poj 2186 强连通入门题目
每头牛的梦想就是成为牛群中最受欢迎的牛. 在一群N(1 <= N <= 10,000)母牛中, 你可以得到M(1 <= M <= 50,000)有序的形式对(A,B),告诉你母 ...
- 树形DP入门题目推荐以及解析
关于树形DP几道入门题目 今天恶补树形DP,感觉海星. 其实挺简单的. 介绍几道例题,我会的. 1.洛谷P1352 没有上司的舞会 我的一篇题解 我们可以考虑每一个节点都是有两种情况. 一个是被邀请: ...
- BZOJ 1001 狼抓兔子 (网络流最小割/平面图的对偶图的最短路)
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 算法讨论: 1.可以用最大流做,最大流等于最小割. 2.可以把这个图转化其对偶图,然 ...
随机推荐
- Mysql5.5升级到5.7的过程已经踩到的坑
https://blog.csdn.net/u014534986/article/details/79699750 故事是这样子的,我们公司有几台老的mysql版本是5.5的,最近项目做了一些升级增加 ...
- git clone和download zip的区别
采用git clone的项目包含.git目录,这里面有历史版本信息 采用下载zip文件的是没有版本历史信息的.只是当前分支的最新版本 克隆指令: $ git clone git://github.co ...
- Spring security用户URL权限之FilterSecurityInterceptor
总: 用户通过浏览器发送URL地址,由FilterSecurityInterceptor判断是否具有相应的访问权限. 对于用户请求的方法权限,例如注解@PreAuthorize("hasRo ...
- linux设备驱动文件结构
struct file, 定义于 <linux/fs.h>, 是设备驱动中第二个最重要的数据结构. 注意 file 与用户空间程序的 FILE 指针没有任何关系. 一个 FILE 定义在 ...
- element ui 批量删除
<el-table :data="tableData" stripe border style="width: 100%" @selection-chan ...
- 2018-8-10-win10-uwp-MVVM-轻量框架
title author date CreateTime categories win10 uwp MVVM 轻量框架 lindexi 2018-08-10 19:17:19 +0800 2018-2 ...
- vue-learning:40 - Vuex - 第一篇:概念和基本使用
vuex 第一篇 目录 vuex概念 state / mapState getter / mapGetter mutation / mapMutation action / mapAction mod ...
- 关于vue-cli打包配置部署404
在vue脚手架(vue-cli)下我很很快的就可以搭建自己的开发环境,但是我们把项目编写完后,需要进行打包上线会遇到各种问题,在根据版本问题,(vue3的版本跟之前相比少了很多配置项),下面是我用老版 ...
- 关于redux和react-redux使用combinereducers之后的问题
最近用react写项目的时候,开始复习之前学过的redux,记录一下一些坑,以防忘记 我现在的redux目录下有这么些东西 首先是index.js import { createStore } fro ...
- 修改jupyter notebook响应的浏览器
Windows下更改jupyter notebook默认响应的浏览器为Chrome 1.命令行下输入:jupyter notebook --generate-config 2.C盘中找到并打开文件:C ...