【解题思路】

  考虑拆点,把每根石柱拆成两个点,具体可以理解为石柱底部和石柱顶部,能爬到石柱顶部的蜥蜴只有有限只,而且蜥蜴只有爬到了石柱顶部才能跳到其他石柱的底部。

  这样,考虑如下建图:

  将每个有蜥蜴的石柱底部和源点连边,容量为1;

  将每个可以跳出边界的石柱顶部和汇点连边,容量为∞;

  将每根石柱顶底相连,容量为该石柱最大承受蜥蜴个数;

  将可以相互跳达的任意两根石柱顶底相连,容量为∞。

  这样,该图的最大流即为最多可逃脱蜥蜴数,最终答案即为总蜥蜴数-最大流,复杂度o(r3c3d2)。

【参考代码】

 #include <bits/stdc++.h>
#define range(i,low,high) for(register int i=(low);i<(high);++i)
#define dange(i,high,low) for(register int i=(high);i>(low);--i) //#define __debug
#ifdef __debug
#define __function__(type) type
#define __procedure__ void
#else
#define __function__(type) __attribute__((optimize("-O2"))) inline type
#define __procedure__ __attribute__((optimize("-O2"))) inline void
#endif using namespace std; static const int N=,M=,INF=0x7f7f7f7f;
static int r,c,d,cardE=; int hed[N+],h[][]; struct edge
{
int fr,to,cap,nxt;
edge(
const int&f=,const int&t=,
const int&c=,const int&x=
):fr(f),to(t),cap(c),nxt(x) {}
}edg[M<<|]; __procedure__ addedge(
const int&fr,const int&to,const int&cp
)
{
edg[cardE]=edge(fr,to,cp,hed[fr]),hed[fr]=cardE++;
}
__procedure__ add_edge(
const int&fr,const int&to,const int&cp
)
{
addedge(fr,to,cp),addedge(to,fr,);
} //SAP {
static const int S=,T=;
int aug[N+],cur[N+],dis[N+],gap[N+],path[N+]; __function__(int) augment()
{
for(int i=T;i!=S;i=edg[path[i]].fr)
{
edg[path[i]].cap-=aug[T],edg[path[i]^].cap+=aug[T];
}
return aug[T];
} __function__(int) SAP(const int&N)
{
memset(aug,,sizeof aug),memset(gap,,sizeof gap);
memset(dis,,sizeof dis),aug[S]=INF,gap[]=N; int ret=;
range(i,,max(N,T)+) cur[i]=hed[i];
for(int fr=S;dis[S]<N;)
{
if(fr==T) fr=S,ret+=augment(); bool flag=;
for(int i=cur[fr];~i;i=edg[i].nxt)
{
int to=edg[i].to;
if(edg[i].cap&&dis[fr]==dis[to]+)
{
aug[to]=min(aug[fr],edg[i].cap),
path[to]=cur[fr]=i,fr=to,flag=; break;
}
}
if(flag)
{
if(!--gap[dis[fr]]) break; dis[fr]=N;
for(int i=hed[fr];~i;i=edg[i].nxt) if(edg[i].cap)
{
dis[fr]=min(dis[fr],dis[edg[i].to]+);
}
++gap[dis[fr]],cur[fr]=hed[fr];
if(fr!=S) fr=edg[path[fr]].fr;
}
}
return ret;
}
//} SAP __function__(bool) ok(const int&x,const int&y)
{
return x+d>=r||x<d||y+d>c||y<=d;
} __function__(int) calc(const int&x,const int&y,const bool&up)
{
return x*c+y+up*(N>>);
} int main()
{
scanf("%d%d%d",&r,&c,&d); int cnt=;
memset(hed,-,sizeof hed);
range(i,,r) range(j,,c+)
{
while(!isdigit(h[i][j]=getchar()));
add_edge(calc(i,j,),calc(i,j,),h[i][j]-='');
}
range(i,,r) range(j,,c+)
{
char ch=getchar();
for(;ch!='.'&&ch!='L';ch=getchar());
if(ch=='L') add_edge(S,calc(i,j,),),++cnt;
}
range(i,,r) range(j,,c+) if(ok(i,j))
{
add_edge(calc(i,j,),T,INF);
}
range(i,,r) range(j,,c+) range(k,-d,d+)
{
int rest=d-abs(k);
range(l,-rest,rest+) if(k||l)
{
int x=i+k,y=j+l;
if(x>=&&x<r&&y>&&y<=c&&h[i][j]&&h[x][y])
{
add_edge(calc(i,j,),calc(x,y,),INF);
}
}
}
return printf("%d\n",cnt-SAP(r*c+<<)),;
}

bzoj1066题解的更多相关文章

  1. [BZOJ1066][luogu_P2472][SCOI2007]蜥蜴

    [BZOJ1066][luogu_P2472][SCOI2007]蜥蜴 试题描述 在一个 \(r\) 行 \(c\) 列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥 ...

  2. 2016 华南师大ACM校赛 SCNUCPC 非官方题解

    我要举报本次校赛出题人的消极出题!!! 官方题解请戳:http://3.scnuacm2015.sinaapp.com/?p=89(其实就是一堆代码没有题解) A. 树链剖分数据结构板题 题目大意:我 ...

  3. noip2016十连测题解

    以下代码为了阅读方便,省去以下头文件: #include <iostream> #include <stdio.h> #include <math.h> #incl ...

  4. BZOJ-2561-最小生成树 题解(最小割)

    2561: 最小生成树(题解) Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1628  Solved: 786 传送门:http://www.lyd ...

  5. Codeforces Round #353 (Div. 2) ABCDE 题解 python

    Problems     # Name     A Infinite Sequence standard input/output 1 s, 256 MB    x3509 B Restoring P ...

  6. 哈尔滨理工大学ACM全国邀请赛(网络同步赛)题解

    题目链接 提交连接:http://acm-software.hrbust.edu.cn/problemset.php?page=5 1470-1482 只做出来四道比较水的题目,还需要加强中等题的训练 ...

  7. 2016ACM青岛区域赛题解

    A.Relic Discovery_hdu5982 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Jav ...

  8. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  9. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

随机推荐

  1. mysql 查询表的最大时间 的数据

    SELECT * from (SELECT MAX(a.update_date) as q ,a.monitoring_point_id from biz_monitoring_point_recor ...

  2. Python--前端之HTML

    html概述和基本结构 HTML概述 HTML是 HyperText Mark-up Language 的首字母简写,意思是超文本标记语言,超文本指的是超链接,标记指的是标签,是一种用来制作网页的语言 ...

  3. 阿里云Linux服务器购买、配置

    购买.配置阿里云Linux服务器配置ftp发布网站全教程 http://blog.csdn.net/Jolesen/article/details/77505840

  4. VIEW当中自定义属性的使用

    主要有三种方法可以实现自定义属性. 第一种方法,直接设置属性值,通过attrs.getAttributeResourceValue拿到这个属性值. (1)在xml文件中设置属性值 [html] vie ...

  5. 【Java架构:基础技术】一篇文章搞掂:Idea

    一.使用技巧 1.1.配置Maven 打开File-Settings打开设置界面 1.2.配置JDK JDK可以设置默认版本,也可以设置针对某个项目 分别对应File-Other Setting-De ...

  6. python re.findall(rule,data),根据左右边界取值url中参数的值

    import re ''' 取值postid,左边界"postid=",右边界"&" ''' url="http://wwww.baidu.c ...

  7. Oracle 用户概念与基本操作

    目录 目录 Oracle的用户 通过系统用户来登陆SQLPlus system和sys的区别 查看登陆的用户 启用和锁定一个用户 启用用户 锁定用户 创建用户 修改用户 删除用户 角色权限 常用的用户 ...

  8. upc组队赛5 Bulbs

    Bulbs 题目描述 Greg has an m × n grid of Sweet Lightbulbs of Pure Coolness he would like to turn on. Ini ...

  9. 点读系列《jmeter官方用户手册》

    官网:http://jmeter.apache.org/usermanual/ 说明:十八元件.十九属性.二十函数,涉及清单内容暂未仔细阅读,个人觉得一是仅供使用参考,二是适合单独写文章来解读 一.让 ...

  10. ActiveX (ocx) 控件 在vs2010 上debug 的方法

    1.在项目的属性中配置Debug,设置调试选项卡中的“命令”.“命令参数”.“工作目录”,“命令”为IE的路径,“命令参数”为自己写的htm页面路径(因htm中未配置ocx路径,所以直接把htm放在了 ...