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. ICSharpCode.SharpZipLib.dll

    using ICSharpCode.SharpZipLib.Checksums; using ICSharpCode.SharpZipLib.Zip; namespace { /// <summ ...

  2. HDU1272小希的迷宫

    小希的迷宫 上次Gardon的迷宫城堡小希玩了很久(见Problem B),现在她也想设计一个迷宫让Gardon来走.但是她设计迷宫的思路不一样,首先她认为所有的通道都应该是双向连通的,就是说如果有一 ...

  3. Winform VS2015打包

    首先 ,我们要去官网http://learn.flexerasoftware.com/content/IS-EVAL-InstallShield-Limited-Edition-Visual-Stud ...

  4. Python 日常报错总结

    本章内容 requests模块报错 执行:res = requests.post(api,mdata = post_data) 报错:SSLError: EOF occurred in violati ...

  5. leetcode 【 Pascal's Triangle 】python 实现

    题目: Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,R ...

  6. 详细的Windows下安装 binwalk

    1. https://github.com/ReFirmLabs/binwalk到这里下载binwalk,下载后解压. 2. 找到下载后的文件夹, 在这里要进行安装步骤,一边按着shift,一边按着鼠 ...

  7. Python-S9-Day124-爬虫&微信

    01 今日内容概要 02 内容回顾:flask上下文 03 内容回顾:多app应用 04 内容回顾:面向对象和数据库 05 内容回顾:爬虫 06 Web微信:获取二维码(一) 07 Web微信:获取二 ...

  8. 利用python爬取58同城简历数据

    利用python爬取58同城简历数据 利用python爬取58同城简历数据 最近接到一个工作,需要获取58同城上面的简历信息(http://gz.58.com/qzyewu/).最开始想到是用pyth ...

  9. 【转】tomcat与apache,tomcat与servlet的区别

    tomcat与apache的区别:(转自:http://blog.csdn.net/longzs/article/details/10959945) 1.apache支持静态页,tomcat支持动态的 ...

  10. 最简单的动态代理实例(spring基于接口代理的AOP原理)

    JDK的动态代理是基于接口的 package com.open.aop; public interface BusinessInterface {     public void processBus ...