题目链接

最大流裸题,没什么好说吧,恰好点数多,考验网络流的效率,正好练\(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]狼抓兔子(最大流)的更多相关文章

  1. BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)

    题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...

  2. BZOJ 1001: [BeiJing2006]狼抓兔子【最大流/SPFA+最小割,多解】

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 23822  Solved: 6012[Submit][ ...

  3. BZOJ 1001: [BeiJing2006]狼抓兔子

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 20029  Solved: 4957[Submit][ ...

  4. BZOJ 1001 [BeiJing2006]狼抓兔子 (UVA 1376 Animal Run)

    1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec  Memory Limit: 162 MBSubmit: 24727  Solved: 6276[Submit][ ...

  5. BZOJ 1001: [BeiJing2006]狼抓兔子(最短路)

    平面图的最小割转化为对偶图的最短路(资料:两极相通——浅析最大最小定理在信息学竞赛中的应用) ,然后DIJKSTRA就OK了. ------------------------------------ ...

  6. BZOJ 1001: [BeiJing2006]狼抓兔子 最小割

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓 ...

  7. 【24.58%】【BZOJ 1001】狼抓兔子

    Time Limit: 15 Sec Memory Limit: 162 MB Submit: 19227 Solved: 4726 [Submit][Status][Discuss] Descrip ...

  8. [bzoj 1001][Beijing2006]狼抓兔子 (最小割+对偶图+最短路)

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...

  9. 1001. [BJOI2006]狼抓兔子【最小割】

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...

  10. 【刷题】BZOJ 1001 [BeiJing2006]狼抓兔子

    Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...

随机推荐

  1. 使用docker国内镜像解决方案

    1:蜂巢镜像 https://c.163yun.com/hub#/m/library/ 例如: docker pull hub.c.163.com/library/nginx:1.8 再次执行dock ...

  2. 3dContactPointAnnotationTool开发日志(二八)

      师姐说物体间不能有穿透,于是我试了下给物体加rigidbody和meshCollider   然后就报错:   说是用meshCollider要么去掉刚体要么就把刚体设置为iskinematic. ...

  3. Mware中CentOS设置静态IP

    Mware中CentOS设置静态IP   因为之前搭建的MongoDB分片没有采用副本集,最近现网压力较大,所以准备研究一下,于是在自己电脑的虚拟机中搭建环境,但是发现之前VMware设置的是DHCP ...

  4. [CB] Windows10为什么质量变差 bug越来越多

    在 Windows 10 发布之后,微软转向了软件即服务模式,每半年释出一个新版本,通过增加更新频率将新的特性不断推送给用户. 在以前,微软产品发布周期是两到三年,其开发流程分成多个阶段:设计和策划. ...

  5. Android四大组件之Intent(续2)

    1.你如何通过一个intent来唤醒activity? this.startActivity(intent,request);      2.什么是显式.隐式的intents? 显式:指定组件名,通常 ...

  6. logstash收集MySQL慢查询日志

    #此处以收集mysql慢查询日志为准,根据文件名不同添加不同的字段值input { file { path => "/data/order-slave-slow.log" t ...

  7. 抽屉点赞及jQuery CSS操作

    1.需要用到的知识点: CSS处理 $('t1').css('color','red') 点赞: -$('t1').append() -$('t1').remove() -setInterval -o ...

  8. [AT2364] [agc012_d] Colorful Balls

    题目链接 AtCoder:https://agc012.contest.atcoder.jp/tasks/agc012_d 洛谷:https://www.luogu.org/problemnew/sh ...

  9. 谈谈 Java 类加载机制

    概述 类加载器主要分为两类,一类是 JDK 默认提供的,一类是用户自定义的. JDK 默认提供三种类加载器: Bootstrap ClassLoader 启动类加载器:每次执行 java 命令时都会使 ...

  10. CentOS 7下安装pptp服务端手记 ok

    主要配置步骤 1. 安装前检查系统支持 2. 安装必要包 3. 修改相关配置文件 4. 设置开机自动启动 pptpd, iptables 5. iptables配置网络 6. 阿里云ECS可能还需要几 ...