【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 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...
随机推荐
- jdbc 5.0
1.事务 事务将单个SQL语句或一组SQL语句视为一个逻辑单元,如果任何语句失败,整个事务将失败. jdbc的MySQL驱动程序中的事务默认是自动提交. 默认情况下,每个SQL语句在完成后都会提交到数 ...
- PXE推一半失败,HP服务器、曙光服务器删除数据
一.#设备:惠普HP DL380 Gen9 PXE安装失败,系统尝试从硬盘启动 需要将安装未完整的系统数据删除,以便正常装机 从控制台重启设备 重启后,HP在此界面选择Intelligent Prov ...
- linux设置时区和自动同步时间
1.设置时区 编辑 /etc/sysconfig/clock 修改 ZONE="Asia/Shanghai" 然后 cp /usr/share/zoneinfo/Asia/Sh ...
- utuntu下安装eclipse+jdk
安装jdk: 1.下载一个可以用的jdk压缩包.下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads- ...
- Sql Server统计报表案例
场景:查询人员指定年月工作量信息 USE [Test] GO SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER procedure [dbo ...
- [LeetCode] PathSum
Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all ...
- 对Spark2.2.0文档的学习2-Job Scheduling
Job Scheduling Link:http://spark.apache.org/docs/2.2.0/job-scheduling.html 概况: (1)集群中多个应用的调度主要考虑的是不同 ...
- OGG内部进程介绍
1.首先看看什么是OGG,以及OGG的用途 简单的来讲 Oracle Golden Gate (简称OGG)是一种基于日志的结构化数据复制备份软件,它通过解析源数据库在线日志或归档日志获得 ...
- [二]SpringBoot 之 简单的接口
(1)编写一个实体类Demo package me.shijunjie.entity; public class Demo { private long id; private String name ...
- vim在行首和 行尾加
在每行开始加入“<a href=” vim 命令: :%s/^/<a href=/g 在每行尾加入 “</a>” vim命令 : ...