BZOJ1001 狼抓兔子

【题目描述】

现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形:  左上角点为(1,1),右下角点为(N,M)(上图中N=4,M=5).有以下三种类型的道路 1:(x,y)<==>(x+1,y) 2:(x,y)<==>(x,y+1) 3:(x,y)<==>(x+1,y+1) 道路上的权值表示这条路上最多能够通过的兔子数,道路是无向的. 左上角和右下角为兔子的两个窝,开始时所有的兔子都聚集在左上角(1,1)的窝里,现在它们要跑到右下解(N,M)的窝中去,狼王开始伏击这些兔子.当然为了保险起见,如果一条道路上最多通过的兔子数为K,狼王需要安排同样数量的K只狼,才能完全封锁这条道路,你需要帮助狼王安排一个伏击方案,使得在将兔子一网打尽的前提下,参与的狼的数量要最小。因为狼还要去找喜羊羊麻烦.

【输入文件】

第一行为N,M.表示网格的大小,N,M均小于等于1000.接下来分三部分第一部分共N行,每行M-1个数,表示横向道路的权值. 第二部分共N-1行,每行M个数,表示纵向道路的权值. 第三部分共N-1行,每行M-1个数,表示斜向道路的权值. 输入文件保证不超过10M
【输出文件】
输出一个整数,表示参与伏击的狼的最小数量.
【输入样例】
3 4
5 6 4
4 3 1
7 5 3
5 6 7 8
8 7 6 5
5 5 5
6 6 6
【输出样例】
14
【题目分析】
我首先表示这个题我不是自己做出来的= =,看了网上的题解才会。
这个题的模型是最小割,然后转化成最短路的模型来解(最大流算法不足以解决这么多点的流)
最小割的模型比较简单,就是如图所示的图做一遍最大流就行了。
根据周冬的论文……一个平面图的最小割可以转化成它的对偶图的最短路来做(有不对之处请大牛指正),于是重新构图,虚拟一个源点和一个终点 ,把每个三角形作为点,有公共边就连边,有左边界或下边界的与源点连边,有上边界和右边界的与终点连边,做一遍最短路就行了。
【代码实现】
Code
  1 program aaa;
  2 const maxn=5000000;
  3 type bian=record
  4        y,next,l:longint;
  5      end;
  6 var a:array[0..6000000]of bian;
  7     dist,d,g:array[0..2000000]of longint;
  8     b:array[0..1000,0..1000,0..1]of longint;
  9     v:array[0..2000000]of boolean;
 10     i,j,m,n,ans,x,y,l,tot,sum,tt:longint;
 11 procedure insert(x,y,l:longint);
 12 begin
 13     inc(tot);
 14     a[tot].y:=y;
 15     a[tot].l:=l;
 16     a[tot].next:=g[x];
 17     g[x]:=tot;
 18 end;
 19 procedure spfa;
 20 var t,w,i,j,x:longint;
 21 begin
 22     fillchar(dist,sizeof(dist),63);
 23     d[0]:=0;t:=0;w:=0;v[0]:=true;dist[0]:=0;
 24     while t<>w+1 do
 25     begin
 26         x:=d[t];inc(t);v[x]:=false;
 27         if t=maxn then t:=0;
 28         i:=g[x];
 29         while i<>0 do
 30         begin
 31             j:=a[i].y;
 32             if dist[x]+a[i].l<dist[j] then
 33             begin
 34                 dist[j]:=dist[x]+a[i].l;
 35                 if not v[j] then
 36                 begin
 37                     if dist[j]<dist[d[t]] then
 38                     begin
 39                         dec(t);
 40                         if t=-1 then t:=maxn-1;
 41                         d[t]:=j;
 42                     end
 43                     else
 44                     begin
 45                         inc(w);
 46                         if w=maxn then w:=0;
 47                         d[w]:=j;
 48                     end;
 49                     v[j]:=true;
 50                 end;
 51             end;
 52             i:=a[i].next;
 53         end;
 54     end;
 55 end;
 56 begin
 57     readln(m,n);
 58     for i:=1 to m-1 do
 59       for j:=1 to n-1 do
 60       begin
 61           inc(sum);
 62           b[i,j,0]:=sum;
 63           inc(sum);
 64           b[i,j,1]:=sum;
 65       end;
 66     tt:=sum+1;
 67     for i:=1 to m do
 68       for j:=1 to n-1 do
 69       begin
 70           read(x);
 71           if i=1 then insert(b[i,j,1],tt,x);
 72           if i=m then insert(0,b[i-1,j,0],x);
 73           if (i<>1)and(i<>m) then 
 74           begin
 75               insert(b[i,j,1],b[i-1,j,0],x);
 76               insert(b[i-1,j,0],b[i,j,1],x);
 77           end;
 78       end;
 79     for i:=1 to m-1 do
 80       for j:=1 to n do
 81       begin
 82           read(x);
 83           if j=1 then insert(0,b[i,j,0],x);
 84           if j=n then insert(b[i,j-1,1],tt,x);
 85           if (j<>1)and(j<>n) then
 86           begin
 87               insert(b[i,j,0],b[i,j-1,1],x);
 88               insert(b[i,j-1,1],b[i,j,0],x);
 89           end;
 90       end;
 91     for i:=1 to m-1 do
 92       for j:=1 to n-1 do
 93       begin
 94           read(x);
 95           insert(b[i,j,0],b[i,j,1],x);
 96           insert(b[i,j,1],b[i,j,0],x);
 97       end;
 98     spfa;
 99     writeln(dist[tt]);
100 end.

 

转载于:https://www.cnblogs.com/whitecloth/archive/2012/04/11/2442402.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值