BZOJ1066 [SCOI2007]蜥蜴
首先。。。这是道(很水的)网络流
我们发现"每个时刻不能有两个蜥蜴在同一个柱子上"这个条件是没有用的因为可以让外面的先跳,再让里面的往外跳
但是还有柱子高度的限制,于是把柱子拆点为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]蜥蜴的更多相关文章
- BZOJ1066 SCOI2007 蜥蜴 【网络流-最大流】
BZOJ1066 SCOI2007 蜥蜴 Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离 ...
- bzoj千题计划135:bzoj1066: [SCOI2007]蜥蜴
http://www.lydsy.com/JudgeOnline/problem.php?id=1066 每个柱子拆成两个点 i<<1,i<<1|1,之间连流量为高度的边 如果 ...
- bzoj1066: [SCOI2007]蜥蜴(最大流)
1066: [SCOI2007]蜥蜴 题目:传送门 题解: 哇QTT大佬一眼秒算法...ORT 其实很容易就可以看出来是一道最大流 因为有边的使用限制,那么就可以直接当成是流量来处理嘛 因为是对点进行 ...
- [bzoj1066] [SCOI2007] 蜥蜴 - 网络流
在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距离不超过d的任何一个 ...
- BZOJ1066 [SCOI2007]蜥蜴 网络流 最大流 SAP
由于本题和HDU2732几乎相同,所以读者可以看-> HDU2732题解传送门: http://www.cnblogs.com/zhouzhendong/p/8362002.html
- 【bzoj1066】[SCOI2007]蜥蜴 网络最大流
[bzoj1066][SCOI2007]蜥蜴 Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的 ...
- 【bzoj1066】: [SCOI2007]蜥蜴 图论-最大流
[bzoj1066]: [SCOI2007]蜥蜴 把石柱拆点,流量为高度 然后S与蜥蜴连流量1的边 互相能跳到的石柱连inf的边 石柱能到边界外的和T连inf的边 然后跑dinic就好了 /* htt ...
- [BZOJ1066][luogu_P2472][SCOI2007]蜥蜴
[BZOJ1066][luogu_P2472][SCOI2007]蜥蜴 试题描述 在一个 \(r\) 行 \(c\) 列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥 ...
- 【bzoj1066】【luogu2472】[SCOI2007]蜥蜴
1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec Memory Limit: 162 MB Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上 ...
随机推荐
- 2dx中文乱码问题
我们的代码里面有一个bug 为了跟之前兼容的策划导表工具兼容 导表工具导出的excel全部都是ansi的 为了兼容就只能手动改成utf 8 无bom格式 后来策划嫌烦了 就让在程序段处理这个 研究了好 ...
- iBATIS sql(XML)中的大于、小于、like等符号写法
其实就是xml的特殊符号,因为它的配置就是xml,所以可以用下面这种写法转义 < < > > <> < ...
- JavaWEB 常用开发模式MVC+三层结构
MVC开发模式: M: Model -- JavaBean C: Controler -- Servlet V: View --- JSP 不会在word里面画画,所以就直接截了 老 ...
- iOS - UIImageView
前言 NS_CLASS_AVAILABLE_IOS(2_0) @interface UIImageView : UIView @available(iOS 2.0, *) public class U ...
- Redis基础知识之————空间换时间的查询案例
空间与时间 空间换时间是在数据库中经常出现的术语,简单说就是把查询需要的条件进行索引的存储,然后查询时为O(1)的时间复杂度来快速获取数据,从而达到了使用空间存储来换快速的时间响应!对于redis这个 ...
- maven pom.xml解释 (转)
maven3实战之maven使用入门(编写POM) ---------- maven项目的核心是pom.xml.POM(Project Object Model,项目对象模型)定义了项目的基本信息,用 ...
- C++——string类和标准模板库
一.string类 1.构造函数 string实际上是basic_string<char>的一个typedef,同时省略了与内存管理相关的参数.size_type是一个依赖于实现的整型,是 ...
- Maven最佳实践:划分模块
http://juvenshun.iteye.com/blog/305865 ************************************* "分天下为三十六郡,郡置守,尉,监& ...
- linux下在jar包中找类是否存在
find /usr/lib -name "*.jar" -exec grep -Hsli 类名 {} \;
- python linux 磁盘操作
#coding:utf-8 ''' __author__ = 'similarface' connection:841196883@qq.com 磁盘操作 ''' import psutil impo ...