题目背景

07四川省选

题目描述

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

每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距离不超过d的任何一个石柱上。石柱都不稳定,每次当蜥蜴跳跃时,所离开的石柱高度减1(如果仍然落在地图内部,则到达的石柱高度不变),如果该石柱原来高度为1,则蜥蜴离开后消失。以后其他蜥蜴不能落脚。任何时刻不能有两只蜥蜴在同一个石柱上。

输入输出格式

输入格式:

输入第一行为三个整数r,c,d,即地图的规模与最大跳跃距离。以下r行为石柱的初始状态,0表示没有石柱,1~3表示石柱的初始高度。以下r行为蜥蜴位置,“L”表示蜥蜴,“.”表示没有蜥蜴。

输出格式:

输出仅一行,包含一个整数,即无法逃离的蜥蜴总数的最小值。

输入输出样例

输入样例#1:
复制

5 8 2
00000000
02000000
00321100
02000000
00000000
........
........
..LLLL..
........
........
输出样例#1: 复制

1

说明

100%的数据满足:1<=r, c<=20, 1<=d<=4

首先将每一个石块拆为两个点,容量为其高度;

设源点和汇点,

st 和每一个蜥蜴的位置连容量为1的边,

如果可以跳出自然与ed连inf 的边;

如果在给定的dis范围内,每个点的出与另一个点的入连inf的边;

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<bitset>
#include<ctime>
#include<deque>
#include<stack>
#include<functional>
#include<sstream>
//#include<cctype>
//#pragma GCC optimize(2)
using namespace std;
#define maxn 200005
#define inf 0x3f3f3f3f
//#define INF 1e18
#define rdint(x) scanf("%d",&x)
#define rdllt(x) scanf("%lld",&x)
#define rdult(x) scanf("%lu",&x)
#define rdlf(x) scanf("%lf",&x)
#define rdstr(x) scanf("%s",x)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int U;
#define ms(x) memset((x),0,sizeof(x))
const long long int mod = 1e9 + 7;
#define Mod 1000000000
#define sq(x) (x)*(x)
#define eps 1e-3
typedef pair<int, int> pii;
#define pi acos(-1.0)
const int N = 1005;
#define REP(i,n) for(int i=0;i<(n);i++)
typedef pair<int, int> pii;
inline ll rd() {
ll x = 0;
char c = getchar();
bool f = false;
while (!isdigit(c)) {
if (c == '-') f = true;
c = getchar();
}
while (isdigit(c)) {
x = (x << 1) + (x << 3) + (c ^ 48);
c = getchar();
}
return f ? -x : x;
} ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a%b);
}
ll sqr(ll x) { return x * x; } /*ll ans;
ll exgcd(ll a, ll b, ll &x, ll &y) {
if (!b) {
x = 1; y = 0; return a;
}
ans = exgcd(b, a%b, x, y);
ll t = x; x = y; y = t - a / b * y;
return ans;
}
*/ int n, m;
int st, ed; struct node {
int u, v, nxt, w;
}edge[maxn<<1]; int head[maxn], cnt;
void addedge(int u, int v, int w) {
edge[cnt].u = u; edge[cnt].v = v; edge[cnt].w = w;
edge[cnt].nxt = head[u]; head[u] = cnt++;
}
int rk[maxn]; int bfs() {
queue<int>q;
ms(rk); rk[st] = 1;
q.push(st);
while (!q.empty()) {
int tmp = q.front(); q.pop();
for (int i = head[tmp]; i != -1; i = edge[i].nxt) {
int to = edge[i].v;
if (rk[to] || edge[i].w <= 0)continue;
rk[to] = rk[tmp] + 1; q.push(to);
}
}
return rk[ed];
} int dfs(int u, int flow) {
if (u == ed)return flow;
int add = 0;
for (int i = head[u]; i != -1 && add < flow; i = edge[i].nxt) {
int v = edge[i].v;
if (rk[v] != rk[u] + 1 || !edge[i].w)continue;
int tmpadd = dfs(v, min(edge[i].w, flow - add));
if (!tmpadd) { rk[v] = -1; continue; }
edge[i].w -= tmpadd; edge[i ^ 1].w += tmpadd; add += tmpadd;
}
return add;
} int ans;
void dinic() {
while (bfs())ans += dfs(st, inf);
} int mp[100][100];
int hight[100][100];
int x[maxn], y[maxn];
int fg[1000][1000]; double dis(int a, int b, int x, int y) {
return (a - x)*(a - x) + (b - y)*(b - y);
} double getid(int a, int b) {
return (a - 1)*m + b;
}
int main()
{
//ios::sync_with_stdio(0);
memset(head, -1, sizeof(head));
rdint(n); rdint(m); int d; rdint(d);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char ch; cin >> ch;
hight[i][j] = ch - '0';
}
}
int tot = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
char ch; cin >> ch;
if (ch == 'L') {
fg[i][j] = 1; tot++;// 总的蜥蜴数量
}
}
}
st = 2 * n*m + 1; ed = st + 1;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
int id = getid(i, j);
if (hight[i][j]) {
// 拆点,分为出、入
addedge(id, id + n * m, hight[i][j]);
addedge(id + n * m, id, 0);
if (i + d > n || i - d<1 || j + d>m || j - d < 1) {
// 跳出
addedge(id + n * m, ed, inf);
addedge(ed, id + n * m, 0);
}
if (fg[i][j]) {
addedge(st, id, 1); addedge(id, st, 0);
}
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
for (int a = 1; a <= n; a++) {
for (int b = 1; b <= m; b++) {
if (dis(i, j, a, b) <= d * d) {
int id1 = getid(i, j);
int id2 = getid(a, b);
addedge(id1 + n * m, id2, inf);
addedge(id2, id1 + n * m, 0);
addedge(id2 + n * m, id1, inf);
addedge(id1, id2 + n * m, 0);
}
}
}
}
}
dinic();
cout << tot - ans << endl;
return 0;
}

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

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

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

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

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

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

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

  4. P2472 [SCOI2007]蜥蜴(最大流)

    P2472 [SCOI2007]蜥蜴 自己第一道独立做题且一遍AC的网络流题纪念... 看到这道题我就想到网络流建图的方式了... 首先根据每个高度,我们将每个点拆成两个点限流.之后根据跳的最大距离, ...

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

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

  6. 【BZOJ】1066: [SCOI2007]蜥蜴(最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1066 本题想一想应该懂了的. 我们想啊,,每个点都有限制,每个点都可以跳到另一个有限制的点,每个有蜥 ...

  7. [BZOJ 1066] [SCOI2007] 蜥蜴 【最大流】

    题目链接:BZOJ - 1066 题目分析 题目限制了高度为 x 的石柱最多可以有 x 只蜥蜴从上面跳起,那么就可以用网络流中的边的容量来限制.我们把每个石柱看作一个点,每个点拆成 i1, i2,从 ...

  8. BZOJ 1066:[SCOI2007]蜥蜴(最大流)

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

  9. BZOJ 1066 [SCOI2007]蜥蜴(最大流)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1066 [题目大意] 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些 ...

随机推荐

  1. java 多线程系列基础篇(二)

    概要 本章,我们学习“常用的实现多线程的2种方式”:Thread 和 Runnable.之所以说是常用的,是因为通过还可以通过java.util.concurrent包中的线程池来实现多线程.关于线程 ...

  2. javascript——屏蔽右键快捷菜单

    JS: function menufalse(){ return false; } document.oncontextmenu = menufalse; //禁用快捷菜单 Jquery: $(&qu ...

  3. 【273】利用ArcPy建立处理数据的脚本

    这个脚本可以直接运行处理程序,首先在 ArcPy 上面测试,成功后写入文件,下面的代码实现将指定文件夹内部的栅格数据进行 Calculate Statistics 操作,否则在进行专题图制作的时候会出 ...

  4. Opengl创建机器人手臂代码示例

    /*******************************************************robot.cpp*基于opengl的机械手臂示例代码*s:机械臂逆时针旋转*S:机械臂 ...

  5. Gearman 分布式的异步任务分发框架

    What is Gearman? Gearman provides a generic application framework to farm out work to other machines ...

  6. 简单好用的General开发框架

    1.开篇概述 从2004年学习编程,2007年学习C#以来,做的多半都是跟数据库打交道的工作,所以也积累了很多数据库方面的知识,用过一些ORM框架,从了解掌握到自己实现,慢慢积累了很多代码,直到201 ...

  7. JavaPersistenceWithHibernate第二版笔记-第六章-Mapping inheritance-005Table per subclass with joins(@Inheritance(strategy = InheritanceType.JOINED)、@PrimaryKeyJoinColumn、)

    一.结构 The fourth option is to represent inheritance relationships as SQL foreign key associations. Ev ...

  8. rvm 安装后的补充工作:source $HOME/.profile

    rvm安装后会在 $HOME/.bash_profile 文件追加一行代码: [[ -s "$HOME/.rvm/scripts/rvm" ]] && source ...

  9. 数字图像处理实验(1):PROJECT 02-01, Image Printing Program Based on Halftoning 标签: 图像处理MATLAB 2017-04-2

    实验要求: Image Printing Program Based on Halftoning Objective: To know in principle what is "halft ...

  10. EZOJ #87

    传送门 分析 由于我不知道壶里到底有多少水,那么显然我第一次 分别向两个杯子分别到 L/2 +1 和 L/2 才是最优的.(这样既维护了两个人的差值不超1,又正好倒了L的水).那么接下来如果壶里还有水 ...