蜥蜴 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 蜥蜴
最大流. 建图:首先将每根柱子拆成两个点. 每根柱子的入点向出点连一条容量为柱子高度的边. 每根柱子的出点向可以到达的柱子的入点连一条容量为正无穷的边. 源点向每根初始有蜥蜴的柱子的入点连一条容量为一 ...
随机推荐
- fun下载内容批量收集
1.download title and url #!/usr/bin/env python #-*- coding:utf-8 -*- import re, urllib2,threading de ...
- 你是猴子请来的逗比么!IT跳槽大事件
3月招聘大战早已硝烟四起,互联网职场摇身一变成了跳蚤市场,猎头们告诉跳蚤们,跳不跳不是不问题,往哪儿跳才是重点,跳对了高薪期权都如过眼云烟.不过小编不得不说,劳资最痛恨那些跳槽的人啦!就因为加班 ...
- (转)SpringMVC学习(五)——SpringMVC的参数绑定
http://blog.csdn.net/yerenyuan_pku/article/details/72511611 SpringMVC中的参数绑定还是蛮重要的,所以单独开一篇文章来讲解.本文所有案 ...
- KTU Programming Camp (Winter Training Day 1)
A.B.C(By musashiheart) 0216个人赛前三道题解 E(By ggg) Gym - 100735E Restore H(by pipixia) Gym - 100735H
- faster rcnn需要理解的地方
http://blog.csdn.net/terrenceyuu/article/details/76228317 https://www.cnblogs.com/houkai/p/6824455.h ...
- python基础面试题整理---从零开始 每天十题(03)
一.Q:用Python输出一个Fibonacci数列?(斐波那契额数列) A:我们先来看下代码 #!/usr/bin/env python # -*- coding: utf-8 -*- def fi ...
- javascript中typeof、undefined 和 null
typeof 是运算符,注意不是函数,是运算符,其作用,是考察变量究竟是什么类型.或曰,是变量是否定义或是否初始化的照妖镜.返回值是字符串. undefined 表示一个对象没有被定义或者没有被初始化 ...
- centos7系统root无法通过su切换到某个普通用户
[root@test ~]# su webappsu: failed to execute /bin/bash: Resource temporarily unavailable [root@test ...
- Git学习——从远程库克隆
克隆一个本地库 首先准备好一个远程库.再用命令克隆一个本地库. git clone git@github.com:<github账户>/<远程库名>.git 克隆一个仓库,首先 ...
- Git学习——撤销修改
git checkout -- <file> 当你修改完一个工作区的文件后,使用git status查看当前的状态.其中有说明,接下来你可以git add <file> 去添加 ...