bzoj1412
比较裸的最小割
注意狼和羊的领地可以通过空地相连
const inf=;
dx:array[..] of integer=(,,,-);
dy:array[..] of integer=(-,,,); type node=record
next,point,flow:longint;
end; var edge:array[..] of node;
a,num:array[..,..] of longint;
p,cur,h,numh,pre:array[..] of longint;
n,m,x,y,len,i,j,t,k:longint; function min(a,b:longint):longint;
begin
if a>b then exit(b) else exit(a);
end; procedure add(x,y,f:longint);
begin
inc(len);
edge[len].point:=y;
edge[len].flow:=f;
edge[len].next:=p[x];
p[x]:=len;
end; function sap:longint;
var s,u,i,j,neck,q,tmp:longint;
begin
u:=;
numh[]:=t+;
sap:=;
while h[]<t+ do
begin
if u=t then
begin
i:=;
neck:=inf;
while i<>t do
begin
j:=cur[i];
if neck>edge[j].flow then
begin
neck:=edge[j].flow;
s:=i;
end;
i:=edge[j].point;
end;
i:=;
while i<>t do
begin
j:=cur[i];
dec(edge[j].flow,neck);
inc(edge[j xor ].flow,neck);
i:=edge[j].point;
end;
u:=s;
sap:=sap+neck;
end;
q:=-;
i:=p[u];
while i<>- do
begin
j:=edge[i].point;
if (edge[i].flow>) and (h[u]=h[j]+) then
begin
q:=i;
break;
end;
i:=edge[i].next;
end;
if q<>- then
begin
cur[u]:=q;
pre[j]:=u;
u:=j;
end
else begin
dec(numh[h[u]]);
if numh[h[u]]= then exit;
tmp:=t+;
i:=p[u];
while i<>- do
begin
j:=edge[i].point;
if edge[i].flow> then tmp:=min(tmp,h[j]);
i:=edge[i].next;
end;
h[u]:=tmp+;
inc(numh[h[u]]);
if u<> then u:=pre[u];
end;
end;
end; begin
len:=-;
fillchar(p,sizeof(p),);
readln(n,m);
for i:= to n do
for j:= to m do
begin
read(a[i,j]);
inc(t);
num[i,j]:=t;
end;
inc(t);
for i:= to n do
for j:= to m do
begin
if a[i,j]= then
begin
add(,num[i,j],inf);
add(num[i,j],,);
end
else if a[i,j]= then
begin
add(num[i,j],t,inf);
add(t,num[i,j],);
end;
for k:= to do
begin
x:=i+dx[k];
y:=j+dy[k];
if (x>) and (x<=n) and (y>) and (y<=m) then
begin
if (a[i,j]=) and (a[x,y]<>) then
begin
add(num[i,j],num[x,y],);
add(num[x,y],num[i,j],);
end
else if (a[i,j]=) then
begin
add(num[i,j],num[x,y],);
add(num[x,y],num[i,j],);
end;
end;
end;
end;
writeln(sap);
end.
bzoj1412的更多相关文章
- 【BZOJ1412】狼和羊的故事(网络流)
[BZOJ1412]狼和羊的故事(网络流) 题面 Description "狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......" Orez听 ...
- 【BZOJ1412】[ZJOI2009]狼和羊的故事 最小割
[BZOJ1412][ZJOI2009]狼和羊的故事 Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想: ...
- BZOJ1412 ZJOI2009 狼和羊的故事 【网络流-最小割】
BZOJ1412 ZJOI2009 狼和羊的故事 Description “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和 ...
- 【BZOJ1412】狼和羊的故事(最小割)
题意:将一个由0,1,2构成的矩阵里的1与2全部分割最少需要选取多少条边 n,m<=100 思路:裸的最小割模型 相邻的格子连容量为1的边(其实可以少连很多遍,1与1,2与2之间的边是没有意义的 ...
- LG2598/BZOJ1412 「ZJOI2009」狼和羊的故事 最小割
问题描述 LG2598 BZOJ1412 题解 看到要把狼和羊两个物种分开 自然想到最小割. 发现\((x,y)\)可以向上下左右走以获得贡献,所以建边:\((x,y),(x-1,y)\),\((x, ...
- 嘴巴题3 「BZOJ1412」[ZJOI2009] 狼和羊的故事
「BZOJ1412」[ZJOI2009] 狼和羊的故事 Description "狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......" Or ...
- bzoj1412最小割
太羞耻了,m n写反了(主要是样例n m相等) 建图方法比较高(ji)端(chu),对于可以加栅栏的地方连上1的边,然后求最小割即可 为了让代码优(suo)美(duan),我写了一个check,避免多 ...
- bzoj1412: [ZJOI2009]狼和羊的故事
空地之间开始没有连然后一直WA...题意混乱...尴尬. #include<cstdio> #include<cstring> #include<iostream> ...
- BZOJ1412[ZJOI2009]狼和羊的故事——最小割
题目描述 “狼爱上羊啊爱的疯狂,谁让他们真爱了一场:狼爱上羊啊并不荒唐,他们说有爱就有方向......” Orez听到这首歌,心想:狼和羊如此和谐,为什么不尝试羊狼合养呢?说干就干! Orez的羊狼圈 ...
随机推荐
- 用pycharm开发django项目示例
pycharm开发django工程(一) 在pycharm(企业版)中新建Django工程,注意使用虚拟环境 创建成功后,在pycharm显示的工程目录结构如下: 打开pycharm的Termina ...
- Ubuntu 14.04的SWAP 为0
[@@@@@@]# free total used free shared buffers cached Mem: 1024976 248992 775984 0 16820 73128 -/+ bu ...
- Asp.net之LINQ入门视频教程
当前位置: 主页 > 编程开发 > Asp.net视频教程 > Asp.net之LINQ入门视频教程 > http://www.xin1234.com/Program/Aspn ...
- JS 实现取整
Js 常用数值函数(Math,parseInt)取整 1.丢弃小数部分,保留整数部分parseInt(5/2) 2.向上取整,有小数就整数部分加1Math.ceil(5/2) 3,四舍五入.Mat ...
- 微软职位内部推荐-Sr SDE-MOD-Beijing
微软近期Open的职位: JOB TITLE: Senior Software Design EngineerDEPARTMENT: Microsoft Office Division ChinaIM ...
- 有关hadoop分布式配置详解
linux配置ssh无密码登录 配置ssh无密码登录,先要安装openssh,如下: yum install openssh-clients 准备两台linux服务器或虚拟机,设置两台linux的ho ...
- C++内存泄露调试
我在看DirectX Sample的时候,看到以下代码: // Enable run-time memory check for debug builds. #if defined(DEBUG) | ...
- asp.net web api 开发时应当注意的事项
Self referencing when returning chain of objects. This can be solved using a design pattern called t ...
- centos7 下手动安装MySQL-5.6.32-1.linux_glibc2.5.x86_64.rpm-bundle
由于centos7默认不再是mysql数据库,所以度算手动安装一个. 全程参考http://www.2cto.com/database/201501/371451.html 这里摘抄以下这个链接的内容 ...
- ./configure详解
'configure'脚本有大量的命令行选项.对不同的软件包来说,这些选项可能会有变化,但是许多基本的选项是不会改变的.带上'--help'选项执行'configure'脚本可以看到可用的所有选项.尽 ...