1066

思路:

  网络流最大流;

  拆点,每个点拆成两个,流量为这个点的高度;

  注意,文中说的距离是曼哈顿距离(劳资以为开根号wa了不知道多少次);

  每两个距离不大于d的点连边,流量inf;

  如果距离能够延伸到边界外,就将这个点连向t;

  最后输出,蜥蜴个数减去最大流;

来,上代码:

#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; #define maxn 905
#define INF 0x7ffffff struct NodeType {
int x,y,hi;
};
struct NodeType ai[maxn]; int n,m,cnt=,tot,map[maxn][maxn],s,t,que[maxn*maxn*],tott,d;
int head[maxn],deep[maxn],F[maxn*maxn*],E[maxn*maxn*],V[maxn*maxn*]; inline void edge_add(int u,int v,int f)
{
E[++cnt]=head[u],V[cnt]=v,F[cnt]=f,head[u]=cnt;
E[++cnt]=head[v],V[cnt]=u,F[cnt]=,head[v]=cnt;
} bool bfs()
{
for(int i=s;i<=t;i++) deep[i]=-;
int h=,tail=;que[h]=s,deep[s]=;
while(h<tail)
{
int now=que[h++];
for(int i=head[now];i;i=E[i])
{
if(deep[V[i]]<&&F[i]>)
{
deep[V[i]]=deep[now]+;
if(V[i]==t) return true;
que[tail++]=V[i];
}
}
}
return false;
} int flowing(int now,int flow)
{
if(now==t||flow<=) return flow;
int oldflow=;
for(int i=head[now];i;i=E[i])
{
if(deep[V[i]]==deep[now]+&&F[i]>)
{
int pos=flowing(V[i],min(flow,F[i]));
F[i]-=pos,F[i^]+=pos;
flow-=pos,oldflow+=pos;
if(flow==) return oldflow;
}
}
if(oldflow==) deep[now]=-;
return oldflow;
} int main()
{
scanf("%d%d%d",&n,&m,&d);
char ch[];
for(int i=;i<=n;i++)
{
scanf("%s",ch+);
for(int j=;j<=m;j++)
{
if(ch[j]!='') ai[++tot].x=i,ai[tot].y=j,ai[tot].hi=ch[j]-'',map[i][j]=tot;
}
}
t=tot*+;
for(int i=;i<=tot;i++)
{
edge_add(i,i+tot,ai[i].hi);
for(int j=;j<=tot;j++)
{
if(j==i) continue;
if(abs(ai[i].x-ai[j].x)+abs(ai[i].y-ai[j].y)<=d) edge_add(i+tot,j,INF);
}
if(ai[i].x<=d||ai[i].y<=d||n-ai[i].x+<=d||m-ai[i].y+<=d) edge_add(i+tot,t,INF);
}
for(int i=;i<=n;i++)
{
scanf("%s",ch+);
for(int j=;j<=m;j++) if(ch[j]=='L') edge_add(s,map[i][j],),tott++;
}
int ans=;
while(bfs()) ans+=flowing(s,INF);
cout<<tott-ans;
return ;
}

AC日记——[SCOI2007]蜥蜴 bzoj 1066的更多相关文章

  1. 1066: [SCOI2007]蜥蜴 - BZOJ

    Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平 ...

  2. 蜥蜴 BZOJ 1066

    蜥蜴 [问题描述] 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距 ...

  3. AC日记——[Hnoi2017]影魔 bzoj 4826

    4826 思路: 主席树矩阵加减+单调栈预处理: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 200005 ...

  4. AC日记——[LNOI2014]LCA bzoj 3626

    3626 思路: 离线操作+树剖: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 100005 #defin ...

  5. AC日记——[ZJOI2012]网络 bzoj 2816

    2816 思路: 多个LCT: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 10005 #define l ...

  6. AC日记——[SCOI2009]游戏 bzoj 1025

    [SCOI2009]游戏 思路: 和为n的几个数最小公倍数有多少种. dp即可: 代码: #include <bits/stdc++.h> using namespace std; #de ...

  7. AC日记——[HNOI2014]世界树 bzoj 3572

    3572 思路: 虚树+乱搞: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 300005 #define ...

  8. AC日记——NOI2016区间 bzoj 4653

    4653 思路: 线段树,指针滑动: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 1000005 #def ...

  9. AC日记——Rmq Problem bzoj 3339

    3339 思路: 恶心: 代码: #include <cstdio> #include <cstring> #include <iostream> #include ...

随机推荐

  1. 7款公认比较出色的Python IDE,你值得拥有!

    Python作为一款比较“简洁”的编程语言,它拥有很多性价比高的性能,造就了它现在比较火热的局面,很多人都来学习Python.Python 的学习过程少不了 IDE 或者代码编辑器,或者集成的开发编辑 ...

  2. Python3爬取人人网(校内网)个人照片及朋友照片,并一键下载到本地~~~附源代码

    题记: 11月14日早晨8点,人人网发布公告,宣布人人公司将人人网社交平台业务相关资产以2000万美元的现金加4000万美元的股票对价出售予北京多牛传媒,自此,人人公司将专注于境内的二手车业务和在美国 ...

  3. 使用 CAST

    使用 CAST: CAST ( expression AS data_type ) 使用 CONVERT: CONVERT (data_type[(length)], expression [, st ...

  4. The DOM in JavaScript

    DOM : Document Object Model   D is for document :  The DOM cant work without a document . When you c ...

  5. Python及其常用模块库下载及安装

    一.Python下载:https://www.python.org/downloads/ 二.Python模块下载:http://www.lfd.uci.edu/~gohlke/pythonlibs/ ...

  6. hadoop伪分布式集群的搭建

    集群配置: jdk1.8.0_161 hadoop-2.6.1 linux系统环境:Centos6.5 创建普通用户  dummy 设置静态IP地址 Hadoop伪分布式集群搭建: 为普通用户添加su ...

  7. How to check if Visual Studio 2005 SP1 is installed

    How to check if Visual Studio 2005 SP1 is installed Check the following registry key. HKEY_LOCAL_MAC ...

  8. 55、android app借助友盟实现微信授权登录

    一.去微信开放平台的管理中心申请移动设备的审核(需进行开发者资质认证,每年300元) 1.获取应用的签名 2.在微信开放平台申请移动应用 两个注意点:①签名要填对 ②应用的包名要写对(tips: co ...

  9. fastjosn在低版本丢字段问题

    简单的说: 对于java bean中有字段类似pId这种写法,特征是第一个字母小写,第二个字母大写,在eclipse中生成的getter setter方法是 getpId, setpId. 在低版本的 ...

  10. c#委托使用

    public class StepArgs : EventArgs { public int m_IMax = 0; public int m_IStep = 0; public string m_S ...