【解题思路】

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

  这样,考虑如下建图:

  将每个有蜥蜴的石柱底部和源点连边,容量为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. 【leetcode】987. Vertical Order Traversal of a Binary Tree

    题目如下: Given a binary tree, return the vertical order traversal of its nodes values. For each node at ...

  2. SCP-bzoj-1090

    项目编号:bzoj-1090 项目等级:Safe 项目描述: 戳这里 特殊收容措施: 区间DP.设计状态f[i][j]表示压缩从第i位到第j位的字符串所需的最小长度.转移方式有三种: •初始化:j-i ...

  3. jekins—持续集成

    json转换为Python的字典形式 Martin fowler:通过自动化的构建,编译-发布-自动化测试,尽早的发现集成的错误 持续集成的要素: 统一的代码库 自动构建编译 自动测试(单元测试) 每 ...

  4. html{-webkit-text-size-adjust:none;}(取消浏览器最小字体限制)

    2016年10月13日 09:31:58 ITzhongzi 阅读数 9409   1.当样式表里font-size<12px时,中文版chrome浏览器里字体显示仍为12px,这时可以用 ht ...

  5. 【从0到1,搭建Spring Boot+RESTful API+Shiro+Mybatis+SQLServer权限系统】03、创建RESTful API,并统一处理返回值

    本节应用Spring对RESTful的支持,使用了如@RestController等注解实现RESTful控制器. 如果对Spring中的RESTful不太明白,请查看相关书籍 1.创建一个数据对象, ...

  6. SQL执行计划详解explain

    1.使用explain语句去查看分析结果 如explain select * from test1 where id=1;会出现:id selecttype table type possible_k ...

  7. python format函数的使用

    转载自:http://www.cnblogs.com/kaituorensheng/p/5709970.html python自2.6后,新增了一种格式化字符串函数str.format(),威力十足, ...

  8. java pair配对的概念

    今天在项目中遇到了Pair,之前没有使用过,百度了下,记录. 使用场景 当我们在写一个方法需要返回两个字段值时,我之前的方法是新建一个类或使用集合.目前来看使用Pair方便很多. 配对(Pair).配 ...

  9. 常用内置模块(一)——time、os、sys、random、shutil、pickle、json

    常用内置模块 一.time模块 在python中,时间分为3种       1.时间戳: timestamp,从1970年1月1日到现在的秒数, 主要用于计算两个时间的差    2.localtime ...

  10. 用java api 实现查询 Hive 数据

    版本:cdh5.4.7, hive1.1.0 pom文件 <dependency> <groupId>org.apache.hive</groupId> <a ...