【解题思路】

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

  这样,考虑如下建图:

  将每个有蜥蜴的石柱底部和源点连边,容量为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. QT blockingmaster例子学习

    dialog.h: #ifndef DIALOG_H #define DIALOG_H #include <QDialog> #include "masterthread.h&q ...

  2. 学习java web中的listener

    web.xml里的顺序为:context-param->listener->filter->servlet 监听器是需要新建一个类,然后按监听的对象继承:ServletContext ...

  3. configure: error: libXpm.(a|so) not found

    libXpm-devel明明已经安装过了,libXpm.so之类的也都存在,但是还是一直报这个问题, 百度了很长时间,终于找到了: configure一般的搜索编译路径为/usr/lib/下,因为ph ...

  4. 安卓真机或者模拟器运行安装应用时提示 Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract native libraries, res=-113]解决办法

    有时候为了方便调试APP,会在电脑上开启模拟器来调试我们的代码,有时候会出现 Failure [INSTALL_FAILED_NO_MATCHING_ABIS: Failed to extract n ...

  5. (转)Jupyter默认目录和默认浏览器修改

    目录 1.总结:修改Anaconda中的Jupyter Notebook默认工作路径的三种方式 # 2.Jupyter默认目录和默认浏览器修改 1.总结:修改Anaconda中的Jupyter Not ...

  6. shell 读取配置文件的用法

    https://blog.csdn.net/qq_36684665/article/details/81134179 亲测有用!

  7. 转 MySQL数据库面试问题集锦

    如何设计一个高并发的系统 ① 数据库的优化,包括合理的事务隔离级别.SQL语句优化.索引的优化 ② 使用缓存,尽量减少数据库 IO ③ 分布式数据库.分布式缓存 ④ 服务器的负载均衡 锁的优化策略 ① ...

  8. 在不打开excel的情况下用python执行excel

    import win32com.client import time path = r'absolute dir' #比如填文件的绝对路径,比如d:/file/stock.xlsx xl = win3 ...

  9. Scala 槽点 - require

    require def this(name: String, age: Int) = { this() require(name != null && !name.isEmpty, & ...

  10. CF1216X

    由于rating限制,和慎老师用小号打了一场div 3 从A到F都没啥思维含量..感觉最难想的就是C了?? CF1216C 考完以后想hack一下这道题,然后发现满屏都是分类讨论 我大概是写不动 or ...