bzoj1001
平面图求最小割;
其实看bzoj1001一开始着实把我怔住了
AC的人暴多,可自己完全没思路
后来看了某大牛的ppt,才会做
一个月前做这题的吧,今天来简单回忆一下;
首先是欧拉公式
如果一个连通的平面图有n个点,m条边和f个面,那么f=m-n+2
我们把原图的每个面看成新图的一个点,对于原图中的每条边
如果边只属于一个面,那么给对应点连一个自环;
如果边两侧各有一个面,那么给对应点之间连一条无向边
这样,新图与原图的边一一对应;
可以发现,新图的一条路径对应原图的一个割
于是我们原图起点终点连一条边,增加一个附加面(也可以理解为把外面言直线st分为两个面);
按上述方法建新图,于是最小割问题转化为对新图求最短路;
最短路可以用堆优化dij;
这题我的dij+heap写的有进步
const inf=;
type link=^node;
node=record
po,len:longint;
next:link;
end;
point=record
num,loc:longint;
end; var w:array[..] of link;
heap:array[..] of point;
where,d:array[..] of longint;
xie,hen,shu:array[..,..] of longint;
t,s,i,j,n,m,x,y:longint;
p:link; procedure swap(var a,b:point);
var c:point;
begin
c:=a;
a:=b;
b:=c;
end; procedure add(x,y,z:longint);
var p:link;
begin
new(p);
p^.po:=y;
p^.len:=z;
p^.next:=w[x];
w[x]:=p;
end; procedure up(i:longint);
var j,x,y:longint;
begin
j:=i shr ;
while j> do
begin
if heap[i].num<heap[j].num then
begin
x:=heap[i].loc;
y:=heap[j].loc;
where[x]:=j;
where[y]:=i;
swap(heap[i],heap[j]);
i:=j;
j:=i shr ;
end
else break;
end;
end; procedure sift(i:longint);
var j,x,y:longint;
begin
j:=i shl ;
while j<=s do
begin
if (j+<=s) and (heap[j].num>heap[j+].num) then inc(j);
if heap[i].num>heap[j].num then
begin
x:=heap[i].loc;
y:=heap[j].loc;
where[x]:=j;
where[y]:=i;
swap(heap[i],heap[j]);
i:=j;
j:=i shl ;
end
else break;
end;
end; procedure build; //复杂的建图,这种东西一定要谨慎,错误才会少;
var i:longint;
begin
for i:= to m- do
begin
add(,i+,hen[,i]);
add(i+,,hen[,i]);
end;
for i:= to n- do
begin
x:=(m-)*(*i-)+;
add(,x,shu[i,m]);
add(x,,shu[i,m]);
end; for i:= to m- do
begin
x:=t-m+i;
add(t,x,hen[n,i]);
add(x,t,hen[n,i]);
end;
for i:= to n- do
begin
x:=(m-)*(*i-)+;
add(t,x,shu[i,]);
add(x,t,shu[i,]);
end; for i:= to n- do
for j:= to m- do
begin
x:=(*i-)*(m-)+j+;
y:=x+m-;
add(x,y,hen[i,j]);
add(y,x,hen[i,j]);
end; for i:= to n- do
for j:= to m- do
begin
x:=(*i-)*(m-)+j;
y:=x+m;
add(x,y,shu[i,j]);
add(y,x,shu[i,j]);
end; for i:= to n- do
for j:= to m- do
begin
x:=(*i-)*(m-)+j+;
y:=x+m-;
add(x,y,xie[i,j]);
add(y,x,xie[i,j]);
end;
end; procedure dij; //最短路
var p:link;
mid,k,y:longint;
begin
p:=w[];
for i:= to t do
d[i]:=inf;
d[]:=;
while p<>nil do
begin
x:=p^.po;
d[x]:=min(d[x],p^.len);
p:=p^.next;
end;
s:=;
for i:= to t do
begin
inc(s);
heap[s].num:=d[i];
heap[s].loc:=i; //表示堆的这个位置是哪个点
where[i]:=s; //where表示这个点在堆的哪个位置
up(s);
end; for k:= to t do
begin
mid:=heap[].num;
if s= then break;
if mid=inf then break;
x:=heap[].loc;
y:=heap[s].loc;
where[y]:=; swap(heap[],heap[s]); //退堆
dec(s); sift();
p:=w[x];
while p<>nil do
begin
y:=p^.po;
if d[y]>p^.len+mid then //更新,入堆
begin
d[y]:=p^.len+mid;
heap[where[y]].num:=d[y];
up(where[y]);
end;
p:=p^.next;
end;
end;
end; begin
readln(n,m);
for i:= to n do
begin
for j:= to m- do
read(hen[i,j]);
end;
for i:= to n- do
begin
for j:= to m do
read(shu[i,j]);
end;
for i:= to n- do
begin
for j:= to m- do
read(xie[i,j]);
end; if n= then //注意这种情况要特判
begin
t:=inf;
for i:= to m- do
t:=min(hen[,i],t);
writeln(t);
halt;
end
else if m= then
begin
t:=inf;
for i:= to n- do
t:=min(t,shu[i,]);
writeln(t);
halt;
end;
t:=(n-)*(m-)*+; //计算新图总点数
build;
dij;
writeln(d[t]);
end.
bzoj1001的更多相关文章
- 【bzoj1001】 BeiJing2006—狼抓兔子
http://www.lydsy.com/JudgeOnline/problem.php?id=1001 (题目链接) 题意 给出一张图,求最小割. Solution1 最小割=最大流,所以直接Din ...
- 【BZOJ1001】狼抓兔子(网络流)
[BZOJ1001]狼抓兔子(网络流) 题面 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨, ...
- BZOJ1001 [BeiJing2006]狼抓兔子 最小割 对偶图 最短路
原文链接http://www.cnblogs.com/zhouzhendong/p/8686871.html 题目传送门 - BZOJ1001 题意 长成上面那样的网格图求最小割. $n,m\leq ...
- bzoj1001狼抓兔子 对偶图优化
bzoj1001狼抓兔子 对偶图优化 链接 https://www.lydsy.com/JudgeOnline/problem.php?id=1001 思路 菜鸡总是要填坑的! 很明显让你求网格图的最 ...
- BZOJ1001 BJOI2006狼抓兔子(最小割+最短路)
显然答案就是最小割.直接跑dinic也能过,不过显得不太靠谱. 考虑更正确的做法.作为一个平面图,如果要把他割成两半,那么显然可以用一条曲线覆盖且仅覆盖所有割边.于是我们把空白区域看成点,隔开他们的边 ...
- 【BZOJ1001】[BeiJing2006]狼抓兔子 对偶图最短路
[BZOJ1001][BeiJing2006]狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子 ...
- 【BZOJ1001】狼抓兔子(平面图转对偶图,最短路)
[BZOJ1001]狼抓兔子(平面图转对偶图,最短路) 题面 BZOJ 洛谷 题解 这题用最小割可以直接做 今天再学习了一下平面图转对偶图的做法 大致的思路如下: 1.将源点到汇点中再补一条不与任何线 ...
- BZOJ1001 BeiJing2006 狼抓兔子 【网络流-最小割】*
BZOJ1001 BeiJing2006 狼抓兔子 Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较 ...
- 【bzoj1001】【最短路】【对偶图】【最大流转最小割】狼抓兔子题解
[BZOJ1001]狼抓兔子 1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 18872 Solved ...
随机推荐
- ecshop订单中配送方式报错
警告内容:Warning: number_format() expects parameter 1 to be double, string given in D:\wamp\www\ecshop_o ...
- 利用rlwrap配置linux下oracle sqlplus 历史记录回调
.下载rlwrap wget http://utopia.knoware.nl/~hlub/uck/rlwrap/rlwrap-0.42.tar.gz .解压 tar -xvzf rlwrap-0.4 ...
- JSP 隐藏对象
[摘要] 隐藏对象用在jsp表达式和脚本中,不能直接用在jsp声明中,因为这些隐藏对象是容器在jspservice方法中定义的,在这个方法中定义的变量不能在jsp声明中使用.可以通过参数方法将 ...
- android.support.v7.app.AppCompatActivity
1.Android Studio (api 23) 新建项目的时候 Activity public class MainActivity extends AppCompatActivity 2.系统默 ...
- 【dapper】.net平台下的框架
http://www.cnblogs.com/yipu/archive/2012/11/21/2780199.html Method Duration Remarks Hand coded (usin ...
- WebApi中帮助页Description的中文显示
转自:http://edi.wang/post/2013/10/28/auto-generate-help-document-aspnet-webapi 我选择Web API的一个重要原因就是因为可以 ...
- EXTJS 4.2 资料 控件lable定义
代码: { xtype:'label', id:'label', labelSeparator :'', // 去掉laebl中的冒号 fieldLabel : '这是个label' } 赋值: Ex ...
- Linux Mint SmoothTask2的安装方法
首先,先下载smooth task:点击这里下载 下载之后解压缩,里面有个install文件,点击打开: To install plasmoid unpack archive, go to the d ...
- linux下nginx的安装
一.安装nginx 1.在nginx官方网站下载一个包,下载地址是:http://nginx.org/en/download.html 2.WinSCP(ftp上传工具).exe FT ...
- Workspace in use or cannot be created, choose a different one.--错误解决办法
eclipse 使用一段时间后,有时会因为一些故障自己就莫名奇妙的关闭了,再打开时有时没有问题,有时有会提示错误 Workspace Unavailable: 原因:出现这种情况一般是workspac ...