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 ...
随机推荐
- DB2中循环日期跑数据
1.数据库版本: 2.具体实现方式: ),)) /*************************************************************************** ...
- 关于FileSystemWatcher监听文件创建
FileSystemWatcher中的Created事件不但可以监听用户创建的文件,当用户删除某个文件时,系统会在再监听的那个盘上的回收站创建一个文件,在回收站创建的文件也会触发Created事件,而 ...
- 关于count(1) 和 count(*)
Q:What is the difference between count(1) and count(*) in a sql queryeg.select count(1) from emp; an ...
- Js 获取当前时间
Js获取当前日期时间及其它操作 var myDate = new Date(); myDate.getYear(); //获取当前年份(2位) myDate.getFullYear(); //获取完整 ...
- SPOJ 4487 Splay 基本操作
插入操作,删除操作和置换操作都是单点的,所以不需要lazy标记.这个很简单,都是两次RotateTo,一次Splay操作就搞定. 求最大连续字段和的操作和线段树的题目类似,只需要保存最左边的连续最大字 ...
- 微软职位内部推荐-Pricipal Dev Manager for Application Ecosystem & Service
微软近期Open的职位: Location: China, BeijingDivision: Operations System Group Engineering Group OverviewOSG ...
- doc下批处理文件的感想
这段时间忙着为我们的爬虫程序做一个守护进程,想来想去还是用脚本比较好,所以用了点时间仔细的研究了一下,这里有一点点经验想分享给大家,也不能说是经验了,只能说是我写这个的时候所用到的知识: 1.task ...
- 盒模型------CSS
盒子的内心世界 1.模型 通过CSS的眼睛 在CSS看来,HTML的所有元素都被看成了盒子:段落,标题,块引用,列表,列表项等.甚至内联元素. 盒子的组成 内容区(content):包含内容(文本或图 ...
- 远程登陆MS azure Linux 虚拟机
http://blogs.technet.com/b/uktechnet/archive/2013/11/12/running-a-remote-desktop-on-a-windows-azure- ...
- ExtJS4.2学习(二)Ext统一组件模型——Panel
鸣谢:http://www.shuyangyang.com.cn/jishuliangongfang/qianduanjishu/2013-11-06/171.html --------------- ...