蜥蜴 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 蜥蜴
最大流. 建图:首先将每根柱子拆成两个点. 每根柱子的入点向出点连一条容量为柱子高度的边. 每根柱子的出点向可以到达的柱子的入点连一条容量为正无穷的边. 源点向每根初始有蜥蜴的柱子的入点连一条容量为一 ...
随机推荐
- LintCode 30插入区间
问题 给出一个无重叠的按照区间起始端点排序的区间列表. 在列表中插入一个新的区间,你要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间). 样例 插入区间[2, 5] 到 [[1,2], ...
- spring框架的总结
http://www.cnblogs.com/wangzn/p/6138062.html 大家好,相信Java高级工程师对spring框架都很了解吧!那么我以个人的观点总结一下spring,希望大家有 ...
- WPF知识点全攻略07- 数据绑定(Binding)
数据绑定是WPF不得不提,不得不会系列之一 数据绑定简言之,就是把数据源的数据绑定到目标对象的属性上.目标对象可以是承自DependencyProperty的任何可访问的属性或控件,目标属性必须为依赖 ...
- vue cli的安装与使用
一.简介 vue作为前端开发的热门工具,受到前端开发人员的喜爱.为了简化项目的构建,采用vue cli来简化开发. vue cli是一个全局安装的npm包,提供了终端使用的命令.vue create可 ...
- CPP-基础:C++的new int()与new int[]
编写一个List类: class List { int length; //列表长度 int* lpInt; //列表指针 List(int size); ~List(); } List::List( ...
- 洛谷 P1120 小木棍[数据加强版]
这道题可能是我做过的数据最不水的一道题-- 题目传送门 这题可以说是神剪枝,本身搜索并不算难,但剪枝是真不好想(好吧,我承认我看了题解)-- 剪枝: 用桶来存储木棍 在输入的时候记录下最长的木棍和最短 ...
- 阿里短信接口使用(JAVA版)
近期项目需要使用短信接口,对比下选择了阿里的短信接口 以下为开发笔记: maven pom.xml中引入: <dependency> <groupId>com.aliyun&l ...
- 四. python网络编程
第八章.网络基础知识 1. TCP/IP协议介绍 1.TCP/IP概念 TCP/IP: Transmission Control Protocol/Internet Protocol的简写,中译名为传 ...
- react入门(上)
1. ReactJS是什么? 1). Facebook开源的一个js库 2). 一个用于动态构建用户界面的js库2. React的特点 * Declarative(声明式编码) * Component ...
- ELK踩过的各种坑 6.4版本
一.elasticsearch 1.服务正常启动,但不能正常访问 [root@linux-node1 elasticsearch]# systemctl start elasticsearch [ro ...