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. 893E - Counting Arrays

    E. Counting Arrays time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  2. Codeforces Round #461 (Div. 2) D. Robot Vacuum Cleaner

    D. Robot Vacuum Cleaner time limit per test 1 second memory limit per test 256 megabytes Problem Des ...

  3. 动态规划:HDU-1398-Square Coins(母函数模板)

    解题心得: 1.其实此题有两种做法,动态规划,母函数.个人更喜欢使用动态规划来做,也可以直接套母函数的模板 Square Coins Time Limit: 2000/1000 MS (Java/Ot ...

  4. 使用Spark Streaming + Kudu + Impala构建一个预测引擎

    随着用户使用天数的增加,不管你的业务是扩大还是缩减了,为什么你的大数据中心架构保持线性增长的趋势?很明显需要一个稳定的基本架构来保障你的业务线.当你的客户处在休眠期,或者你的业务处在淡季,你增加的计算 ...

  5. MySQL和PostgreSQL比较

    1.MySQL相对来说比较年轻,首度出现在1994年.它声称自己是最流行的开源数据库.MySQL就是LAMP(用于Web开发的软件包,包括 Linux.Apache及Perl/PHP/Python)中 ...

  6. springboot(七):springboot+mybatis多数据源最简解决方案

    说起多数据源,一般都来解决那些问题呢,主从模式或者业务比较复杂需要连接不同的分库来支持业务.我们项目是后者的模式,网上找了很多,大都是根据jpa来做多数据源解决方案,要不就是老的spring多数据源解 ...

  7. Spring Boot 要点--启动类和热部署

    spring boot需要一个启动类 比如 package com.tianmaying; import org.springframework.boot.SpringApplication; imp ...

  8. unknow table alarmtemp error when drop database (mysql)

    Q: unknow table alarmtemp error when  drop database (mysql) D: alarmtemp is table in rtmd database. ...

  9. 32、详解Android shape的使用方法(转载)

    0.java绘制shape 在官方API介绍中: ShapeDrawable:This object can be defined in an XML file with the <shape& ...

  10. 【Triangle 】cpp

    题目: Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjace ...