首先。。。这是道(很水的)网络流

我们发现"每个时刻不能有两个蜥蜴在同一个柱子上"这个条件是没有用的因为可以让外面的先跳,再让里面的往外跳

但是还有柱子高度的限制,于是把柱子拆点为p1和p2,p1向p2连边,边权为柱子高度

对于相距(注意!是欧几里得距离!)小于d的两个柱子p和q,q2向p1连边,p2向q1连边,边权为inf

S向有蜥蜴的柱子的p1连边,边权为1,可以一步跳出去的柱子p2向T连边,边权为inf

跑最大流即可

 /**************************************************************
Problem: 1066
User: rausen
Language: C++
Result: Accepted
Time:136 ms
Memory:12656 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int N = 1e3 + ;
const int M = N * N;
const int inf = 1e9; struct edge {
int next, to, f;
edge(int _n = , int _t = , int _f = ) : next(_n), to(_t), f(_f) {}
} e[M]; int n, m, D, cnt_p, S, T, ans;
int first[N], tot = ;
int w[][];
int d[N], q[N]; inline void Add_Edges(int x, int y, int f) {
e[++tot] = edge(first[x], y, f), first[x] = tot;
e[++tot] = edge(first[y], x, ), first[y] = tot;
} #define y e[x].to
#define p q[l]
bool bfs() {
static int l, r, x;
memset(d, -, sizeof(d));
d[q[] = S] = ;
for (l = r = ; l != r + ; ++l)
for (x = first[p]; x; x = e[x].next)
if (!~d[y] && e[x].f) {
d[q[++r] = y] = d[p] + ;
if (y == T) return ;
}
return ;
}
#undef p int dfs(int p, int lim) {
if (p == T || !lim) return lim;
int x, tmp, rest = lim;
for (x = first[p]; x && rest; x = e[x].next)
if (d[y] == d[p] + && ((tmp = min(e[x].f, rest)) > )) {
rest -= (tmp = dfs(y, tmp));
e[x].f -= tmp, e[x ^ ].f += tmp;
if (!rest) return lim;
}
if (rest) d[p] = -;
return lim - rest;
}
#undef y inline int Dinic() {
int res = ;
while (bfs())
res += dfs(S, inf);
return res;
} template <class T> T sqr(T x) {
return x * x;
} #define in(x, y) w[x][y] * 2 - 1
#define out(x, y) w[x][y] * 2
int main() {
int i, j, k, l;
char ch;
scanf("%d%d%d", &n, &m, &D);
for (cnt_p = , i = ; i <= n; ++i)
for (j = ; j <= m; ++j) {
ch = getchar();
while (ch < '' || ch > '') ch = getchar();
w[i][j] = ++cnt_p;
if (ch != '') Add_Edges(in(i, j), out(i, j), ch - '');
}
S = cnt_p * + , T = S + ;
for (i = ; i <= n; ++i)
for (j = ; j <= m; ++j)
for (k = ; k <= n; ++k)
for (l = ; l <= m; ++l)
if (sqr(i - k) + sqr(j - l) <= D * D && ((i != k) || (j != l)))
Add_Edges(out(i, j), in(k, l), inf);
for (i = ; i <= n; ++i)
for (j = ; j <= m; ++j) {
ch = getchar();
while (ch != '.' && ch != 'L') ch = getchar();
if (ch == 'L') ++ans, Add_Edges(S, in(i, j), );
if (i <= D || j <= D || i > n - D || j > m - D)
Add_Edges(out(i, j), T, inf);
}
printf("%d\n", ans - Dinic());
return ;
}
#undef in
#undef out

BZOJ1066 [SCOI2007]蜥蜴的更多相关文章

  1. BZOJ1066 SCOI2007 蜥蜴 【网络流-最大流】

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

  2. bzoj千题计划135:bzoj1066: [SCOI2007]蜥蜴

    http://www.lydsy.com/JudgeOnline/problem.php?id=1066 每个柱子拆成两个点 i<<1,i<<1|1,之间连流量为高度的边 如果 ...

  3. bzoj1066: [SCOI2007]蜥蜴(最大流)

    1066: [SCOI2007]蜥蜴 题目:传送门 题解: 哇QTT大佬一眼秒算法...ORT 其实很容易就可以看出来是一道最大流 因为有边的使用限制,那么就可以直接当成是流量来处理嘛 因为是对点进行 ...

  4. [bzoj1066] [SCOI2007] 蜥蜴 - 网络流

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

  5. BZOJ1066 [SCOI2007]蜥蜴 网络流 最大流 SAP

    由于本题和HDU2732几乎相同,所以读者可以看-> HDU2732题解传送门: http://www.cnblogs.com/zhouzhendong/p/8362002.html

  6. 【bzoj1066】[SCOI2007]蜥蜴 网络最大流

    [bzoj1066][SCOI2007]蜥蜴 Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的 ...

  7. 【bzoj1066】: [SCOI2007]蜥蜴 图论-最大流

    [bzoj1066]: [SCOI2007]蜥蜴 把石柱拆点,流量为高度 然后S与蜥蜴连流量1的边 互相能跳到的石柱连inf的边 石柱能到边界外的和T连inf的边 然后跑dinic就好了 /* htt ...

  8. [BZOJ1066][luogu_P2472][SCOI2007]蜥蜴

    [BZOJ1066][luogu_P2472][SCOI2007]蜥蜴 试题描述 在一个 \(r\) 行 \(c\) 列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥 ...

  9. 【bzoj1066】【luogu2472】[SCOI2007]蜥蜴

    1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec  Memory Limit: 162 MB Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上 ...

随机推荐

  1. hdu 1568 Fibonacci 快速幂

    Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  2. PhpStorm的注册码、Key

    下面是PhpStorm的注册码.Key,其license由用户名和License值组成. User name: EMBRACE License key: ===== LICENSE BEGIN === ...

  3. shift移动变量

    1.移动变量 脚本 sh05.sh #!/bin/bash # Program # Program shows the effect of shift function # History: # // ...

  4. iOS - UIControl

    前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIControl : UIView @available(iOS 2.0, *) public class UIC ...

  5. Data truncation: Truncated incorrect DOUBLE value 解决方案

    1.情况限制 此处的错误解决方案只讨论: 在使用Mybatis时,传入数组且使用<foreach>标签时出现此种报错: 2.报错案例 mapper.java /** * @Descript ...

  6. DOM加载:浏览器渲染和操作顺序(转载 学习中。。。)

    DOM加载:浏览器渲染和操作顺序 1.HTML解析完毕 2.外部脚本和样式表加载完毕 3.脚本在文档内解析并执行 4.HTML DOM完全构造起来 5.图片和外部内容加载 6.网页完成加载 基于这个顺 ...

  7. spring的初始化bean,销毁bean之前的操作详解

    我所知道的在spring初始化bean,销毁bean之前的操作有三种方式: 第一种:通过@PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作 第二种是 ...

  8. Kafka文件的存储机制

    Kafka文件的存储机制 同一个topic下有多个不同的partition,每个partition为一个目录,partition命名的规则是topic的名称加上一个序号,序号从0开始. 每一个part ...

  9. HTTP 头部解释

    1. Accept:告诉WEB服务器自己接受什么介质类型,*/* 表示任何类型,type/* 表示该类型下的所有子类型,type/sub-type. 2. Accept-Charset:浏览器申明自己 ...

  10. OA系统部门结构树

    public class DepartmentUtils { /** * @param topList 顶级部门列表 * @param removeId 删除部门的id * @return */ pu ...