蜥蜴 BZOJ 1066
蜥蜴
【问题描述】
在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外。 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到平面距离不超过d的任何一个石柱上。石柱都不稳定,每次当蜥蜴跳跃时,所离开的石柱高度减1(如果仍然落在地图内部,则到达的石柱高度不变),如果该石柱原来高度为1,则蜥蜴离开后消失。以后其他蜥蜴不能落脚。任何时刻不能有两只蜥蜴在同一个石柱上。
【输入格式】
输入第一行为三个整数r,c,d,即地图的规模与最大跳跃距离。以下r行为石竹的初始状态,0表示没有石柱,1~3表示石柱的初始高度。以下r行为蜥蜴位置,“L”表示蜥蜴,“.”表示没有蜥蜴。
【输出格式】
输出仅一行,包含一个整数,即无法逃离的蜥蜴总数的最小值。
【样例输入】
5 8 2
00000000
02000000
00321100
02000000
00000000
........
........
..LLLL..
........
........
【样例输出】
1
【数据范围】
100%的数据满足:1<=r, c<=20, 1<=d<=4
题解:
题目中石柱的高度其实就是限制了点的通过次数
那么把每一个点拆成两个点,分别是进入点和离开点
每个进入点向对应的离开点连一条容量为石柱高度的边
每个离开点向能跳到的进入点连一条容量为无限的边
源点向每个有蜥蜴的进入点连一条容量为1的边
每个能跳出边界的离开点向汇点连一条容量为无限的边
跑一遍最大流
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
using namespace std;
inline int Get()
{
int x;
char c;
while((c = getchar()) < '' || c > '');
x = c - '';
while((c = getchar()) >= '' && c <= '') x = x * + c - '';
return x;
}
const int inf = ;
const int me = ;
int r, c, d, n;
int num;
int S, T;
struct shape
{
int x, y;
};
shape pos[me];
int point[][];
int tot = , nex[me], fir[me], to[me], val[me];
inline void Add(const int &x, const int &y, const int &z)
{
nex[++tot] = fir[x];
fir[x] = tot;
to[tot] = y;
val[tot] = z;
}
inline void Ins(const int &x, const int &y, const int &z)
{
Add(x, y, z);
Add(y, x, );
}
inline int Min(const int &x, const int &y)
{
return (x < y) ? x : y;
}
inline int Sqr(const int &x)
{
return x * x;
}
int dep[me], que[me];
inline bool Bfs()
{
int t = , w = ;
memset(dep, -, sizeof(dep));
que[++w] = S;
dep[S] = ;
while(t < w)
{
int u = que[++t];
for(int i = fir[u]; i; i = nex[i])
{
int v = to[i];
if(dep[v] == - && val[i])
{
dep[v] = dep[u] + ;
que[++w] = v;
if(v == T) return true;
}
}
}
return false;
}
int Dinic(const int &u, const int &flow)
{
if(u == T || !flow) return flow;
int wa = ;
for(int i = fir[u]; i; i = nex[i])
{
int v = to[i];
if(dep[v] == dep[u] + && val[i])
{
int go = Dinic(v, Min(flow - wa, val[i]));
if(go)
{
val[i] -= go;
val[i ^ ] += go;
wa += go;
if(wa == flow) break;
}
}
}
return wa;
}
char s[me];
int main()
{
r = Get(), c = Get(), d = Get();
n = r * c;
S = , T = n << | ;
for(int i = ; i <= r; ++i)
{
scanf("%s", s);
for(int j = ; j <= c; ++j)
{
int sa = s[j - ] - '';
if(sa)
{
point[i][j] = ++num;
pos[num] = (shape) {i, j};
Ins(num, num + n, sa);
int dis = Min(i, Min(j, Min(r - i + , c - j + )));
if(dis <= d) Ins(num + n, T, inf);
for(int k = ; k < num; ++k)
{
int x = pos[k].x, y = pos[k].y;
double dist = sqrt(Sqr(x - i) + Sqr(y - j));
if(dist <= d)
{
Ins(point[x][y] + n, num, inf);
Ins(num + n, point[x][y], inf);
}
}
}
}
}
int ans = ;
for(int i = ; i <= r; ++i)
{
scanf("%s", s);
for(int j = ; j <= c; ++j)
if(s[j - ] == 'L')
{
++ans;
Ins(S, point[i][j], );
}
}
while(Bfs()) ans -= Dinic(S, inf);
printf("%d", ans);
}
蜥蜴 BZOJ 1066的更多相关文章
- AC日记——[SCOI2007]蜥蜴 bzoj 1066
1066 思路: 网络流最大流: 拆点,每个点拆成两个,流量为这个点的高度: 注意,文中说的距离是曼哈顿距离(劳资以为开根号wa了不知道多少次): 每两个距离不大于d的点连边,流量inf: 如果距离能 ...
- [BZOJ 1066] [SCOI2007] 蜥蜴 【最大流】
题目链接:BZOJ - 1066 题目分析 题目限制了高度为 x 的石柱最多可以有 x 只蜥蜴从上面跳起,那么就可以用网络流中的边的容量来限制.我们把每个石柱看作一个点,每个点拆成 i1, i2,从 ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
- BZOJ 1066 POJ 2711 [SCOI2007]蜥蜴
与POJ 1815 Friendship类似,该题之前也做过 目前处于TLE状态.样例已经通过 1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec Memory Limit: ...
- poj 2711 Leapin' Lizards && BZOJ 1066: [SCOI2007]蜥蜴 最大流
题目链接:http://poj.org/problem?id=2711 题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1066 Your p ...
- BZOJ 1066: [SCOI2007]蜥蜴( 最大流 )
结点容量..拆点然后随便写 --------------------------------------------------------------- #include<cstdio> ...
- BZOJ 1066 蜥蜴 最大流
题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1066 题目大意: 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥 ...
- BZOJ 1066 [SCOI2007]蜥蜴(最大流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1066 [题目大意] 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些 ...
- bzoj 1066 蜥蜴
最大流. 建图:首先将每根柱子拆成两个点. 每根柱子的入点向出点连一条容量为柱子高度的边. 每根柱子的出点向可以到达的柱子的入点连一条容量为正无穷的边. 源点向每根初始有蜥蜴的柱子的入点连一条容量为一 ...
随机推荐
- 一条SQL语句在MySQL中是如何执行的
概览 本篇文章会分析下一个sql语句在mysql中的执行流程,包括sql的查询在mysql内部会怎么流转,sql语句的更新是怎么完成的. 一.mysql架构分析 mysql主要分为Server层和存储 ...
- 如何在Ubuntu 16.04上安装Apache Web服务器
转载自:https://www.howtoing.com/how-to-install-the-apache-web-server-on-ubuntu-16-04 介绍 Apache HTTP服务器是 ...
- 快学UiAutomator新建第一个测试工程
1.打开Eclipse 2.新建一个java项目,包 3.增加build path,加载需要的库文件jar包 4.新建测试类,继承UIAutomatorTestCase 5.编写测试用例,方法名必须t ...
- 二分查找 && 三分查找
LeetCode34. Find First and Last Position of Element in Sorted Array 题意:找出指定元素出现的范围,Ologn 思路:两次二分 cla ...
- House of Spirit(fastbin)
0x01 fastbin fastbin所包含chunk的大小为16 Bytes, 24 Bytes, 32 Bytes, … , 80 Bytes.当分配一块较小的内存(mem<=64 Byt ...
- 安装pycharm 2018.3 Professional Edition
1.下载pycharm 2018.3 Professional 2.下载破解补丁,Gitee仓库 或 直接下载(Direct download link) ,并放到pycharm目录下的\bin目录( ...
- Clover启动mbr的win7/win8
对以传统bios安装在mbr分区的win7/WIN8也可以使用EFI引导直接进入win.首先进win提取EFI引导文件,以管理员员身份运行cmd,输入如下命令 bcdboot c:\windows / ...
- [LUOGU] P1387 最大正方形
题目描述 在一个n*m的只包含0和1的矩阵里找出一个不包含0的最大正方形,输出边长. 输入输出格式 输入格式: 输入文件第一行为两个整数n,m(1<=n,m<=100),接下来n行,每行m ...
- [LUOGU] P1880 [NOI1995]石子合并
题目描述 在一个圆形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次只能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个算法,计算出将N堆石子合并成1 ...
- Django REST framework 中的视图
1.Request REST framework传入视图的request对象不再是Django默认的Httprequest对象,而是DRF提供的扩展类的Request类的对象 常用属性 request ...