【BZOJ 1001】[BJOI2006]狼抓兔子(最大流)
题目链接
最大流裸题,没什么好说吧,恰好点数多,考验网络流的效率,正好练\(Dinic\)。
#include <cstdio>
#include <queue>
#include <cstring>
#define INF 2147483647
using namespace std;
const int MAXN = 1000010;
const int MAXM = 8000010;
inline int read(){
int s = 0, w = 1;
char ch = getchar();
while(ch < '0' || ch > '9'){ if(ch == '-') w = -1; ch = getchar(); }
while(ch >= '0' && ch <= '9'){ s = s * 10 + ch - '0'; ch = getchar(); }
return s * w;
}
struct Edge{
int next, to, rest;
}e[MAXM];
int s, t, num = 1, n, m;
int head[MAXN];
inline void Add(int from, int to, int flow){
e[++num] = (Edge){ head[from], to, flow }; head[from] = num;
e[++num] = (Edge){ head[to], from, flow }; head[to] = num;
}
int level[MAXN], now, sum;
queue <int> q;
int re(){
memset(level, 0, sizeof level);
while(q.size()) q.pop();
q.push(s); level[s] = 1;
while(q.size()){
now = q.front(); q.pop();
for(int i = head[now]; i; i = e[i].next)
if(e[i].rest && !level[e[i].to]){
level[e[i].to] = level[now] + 1;
q.push(e[i].to);
}
}
return level[t];
}
int findflow(int u, int flow){
if(!flow || u == t) return flow;
int f = 0, t;
for(int i = head[u]; i; i = e[i].next){
if(e[i].rest && level[e[i].to] == level[u] + 1){
f += (t = findflow(e[i].to, min(flow - f, e[i].rest)));
e[i].rest -= t; e[i ^ 1].rest += t;
}
}
if(!f) level[u] = 0;
return f;
}
int dinic(){
int ans = 0;
while(re())
ans += findflow(s, INF);
return ans;
}
inline int id(int i, int j){
return (i - 1) * m + j;
}
int main(){
n = read(); m = read(); s = id(1, 1); t = id(n, m);
for(int i = 1; i <= n; ++i)
for(int j = 1; j < m; ++j)
Add(id(i, j), id(i, j + 1), read());
for(int i = 1; i < n; ++i)
for(int j = 1; j <= m; ++j)
Add(id(i, j), id(i + 1, j), read());
for(int i = 1; i < n; ++i)
for(int j = 1; j < m; ++j)
Add(id(i, j), id(i + 1, j + 1), read());
printf("%d\n", dinic());
return 0;
}
【BZOJ 1001】[BJOI2006]狼抓兔子(最大流)的更多相关文章
- BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)
题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...
- BZOJ 1001: [BeiJing2006]狼抓兔子【最大流/SPFA+最小割,多解】
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 23822 Solved: 6012[Submit][ ...
- BZOJ 1001: [BeiJing2006]狼抓兔子
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 20029 Solved: 4957[Submit][ ...
- BZOJ 1001 [BeiJing2006]狼抓兔子 (UVA 1376 Animal Run)
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 24727 Solved: 6276[Submit][ ...
- BZOJ 1001: [BeiJing2006]狼抓兔子(最短路)
平面图的最小割转化为对偶图的最短路(资料:两极相通——浅析最大最小定理在信息学竞赛中的应用) ,然后DIJKSTRA就OK了. ------------------------------------ ...
- BZOJ 1001: [BeiJing2006]狼抓兔子 最小割
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓 ...
- 【24.58%】【BZOJ 1001】狼抓兔子
Time Limit: 15 Sec Memory Limit: 162 MB Submit: 19227 Solved: 4726 [Submit][Status][Discuss] Descrip ...
- [bzoj 1001][Beijing2006]狼抓兔子 (最小割+对偶图+最短路)
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...
- 1001. [BJOI2006]狼抓兔子【最小割】
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...
- 【刷题】BZOJ 1001 [BeiJing2006]狼抓兔子
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...
随机推荐
- IP ,路由
ifconfig 命令 ip信息 enp0s3: flags=4163<UP(已经启用),BROADCAST(支持广播),RUNNING,MULTICAST(支持多播)> ...
- Hash(散列函数)简单应用引出解决散列冲突的四种方法
商店允许顾客通过电话订购商品,并在几天后上门自取.商店的数据库使用客户的电话号码作为其检索的关键字(客户知道自己的电话号码,而且这些电话关键字几乎是唯一的).如何组织商店的数据库,以允许更加高效的进行 ...
- (十三)Jmeter之Bean Shell 的使用(二)
该文章来自:http://www.cnblogs.com/puresoul/p/5092628.html 上一篇Jmeter之Bean shell使用(一)简单介绍了下Jmeter中的Bean she ...
- mysql 数据类型 及 常用命令
一.数据类型 1.整型 数据类型 存储空间 说明 取值范围 TINYINT 1字节 非常小的整数 带符号值:-128~127 无符号值:0~255 SMALLINT 2字节 较小的整数 带符号值:-3 ...
- Java多线程 -sleep 用法详解
阿里面试官问我这个问题,我仔细总结了一下: 参考:sleep.yield.wait.join的区别(阿里面试) 我们可能经常会用到 Thread.Sleep 函数来使线程挂起一段时间.那么你有没有正确 ...
- [十二]SpringBoot 之 servlet
Web开发使用 Controller 基本上可以完成大部分需求,但是我们还可能会用到 Servlet.Filter.Listener.Interceptor 等等. 当使用spring-Boot时,嵌 ...
- 洛谷 P1352 没有上司的舞会
树形动规入门题 先放题面 题目描述 某大学有N个职员,编号为1~N.他们之间有从属关系,也就是说他们的关系就像一棵以校长为根的树,父结点就是子结点的直接上司.现在有个周年庆宴会,宴会每邀请来一个职员都 ...
- 洛谷 P2057 善意的投票(网络流最小割)
P2057 善意的投票 题目描述 幼儿园里有n个小朋友打算通过投票来决定睡不睡午觉.对他们来说,这个问题并不是很重要,于是他们决定发扬谦让精神.虽然每个人都有自己的主见,但是为了照顾一下自己朋友的想法 ...
- [codeforces743E]Vladik and cards
E. Vladik and cards time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 线段树之Sum
题面: 给定一数列,规定有两种操作,一是修改某个元素,二是求区间的连续和. Input: 输入数据第一行包含两个正整数n,m(n<=100000,m<=500000),以下是m行, 每行有 ...