[SCOI2007]蜥蜴 BZOJ1066 最大流
题目背景
07四川省选
题目描述
在一个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
首先将每一个石块拆为两个点,容量为其高度;
设源点和汇点,
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 最大流的更多相关文章
- 【bzoj1066】[SCOI2007]蜥蜴 网络最大流
[bzoj1066][SCOI2007]蜥蜴 Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的 ...
- 【bzoj1066】: [SCOI2007]蜥蜴 图论-最大流
[bzoj1066]: [SCOI2007]蜥蜴 把石柱拆点,流量为高度 然后S与蜥蜴连流量1的边 互相能跳到的石柱连inf的边 石柱能到边界外的和T连inf的边 然后跑dinic就好了 /* htt ...
- bzoj1066: [SCOI2007]蜥蜴(最大流)
1066: [SCOI2007]蜥蜴 题目:传送门 题解: 哇QTT大佬一眼秒算法...ORT 其实很容易就可以看出来是一道最大流 因为有边的使用限制,那么就可以直接当成是流量来处理嘛 因为是对点进行 ...
- P2472 [SCOI2007]蜥蜴(最大流)
P2472 [SCOI2007]蜥蜴 自己第一道独立做题且一遍AC的网络流题纪念... 看到这道题我就想到网络流建图的方式了... 首先根据每个高度,我们将每个点拆成两个点限流.之后根据跳的最大距离, ...
- BZOJ1066 [SCOI2007]蜥蜴 网络流 最大流 SAP
由于本题和HDU2732几乎相同,所以读者可以看-> HDU2732题解传送门: http://www.cnblogs.com/zhouzhendong/p/8362002.html
- 【BZOJ】1066: [SCOI2007]蜥蜴(最大流)
http://www.lydsy.com/JudgeOnline/problem.php?id=1066 本题想一想应该懂了的. 我们想啊,,每个点都有限制,每个点都可以跳到另一个有限制的点,每个有蜥 ...
- [BZOJ 1066] [SCOI2007] 蜥蜴 【最大流】
题目链接:BZOJ - 1066 题目分析 题目限制了高度为 x 的石柱最多可以有 x 只蜥蜴从上面跳起,那么就可以用网络流中的边的容量来限制.我们把每个石柱看作一个点,每个点拆成 i1, i2,从 ...
- BZOJ 1066:[SCOI2007]蜥蜴(最大流)
蜥蜴Description在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴可以跳到 ...
- BZOJ 1066 [SCOI2007]蜥蜴(最大流)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=1066 [题目大意] 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些 ...
随机推荐
- DAY19-Pillow制作验证码
PIL:Python Imaging Library,已经是Python平台事实上的图像处理标准库了.PIL功能非常强大,但API却非常简单易用. 由于PIL仅支持到Python 2.7,加上年久失修 ...
- startactivityforresult使用
与startactivity基本相同,不过需要传入(intent,int)第二个int为请求ID,用来识别 在该activity中还应该重写nActivityResult(int requestCod ...
- 深入理解js的变量提升和函数提升(转)
一.变量提升 在ES6之前,JavaScript没有块级作用域(一对花括号{}即为一个块级作用域),只有全局作用域和函数作用域.变量提升即将变量声明提升到它所在作用域的最开始的部分.上个简历的例子如: ...
- bzoj 1568 李超线段树
博客:http://www.cnblogs.com/mangoyang/p/9979465.html 李超线段树支持两种操作:1:插入一条直线.2:询问在x = c与这些直线的交点中最大的y坐标. 插 ...
- JS Number类型数字位数及IEEE754标准
JS的基础类型Number,遵循 IEEE 754 规范,采用双精度存储(double precision),占用 64 bit.如图 意义 1位用来表示符号位 11位用来表示指数 52位表示尾数 浮 ...
- ElasticSearch 入门(转)
最大的特点: 1. 数据库的 database, 就是 index 2. 数据库的 table, 就是 tag 3. 不要使用browser, 使用curl来进行客户端操作. 否则会出现 jav ...
- scala中的self type
scala目前的书籍有两<快学scala>和<scala编程>.资料确实不多,对这个语法使用只能结合使用进行理解. 先看源码: private[spark] trait Act ...
- wordCount总结
1.github地址:https://github.com/husterSyy/SoftTest 2.PSP表格 psp 2.1 psp阶段 预估耗时(分钟) 实际耗时(分钟) Planning ...
- 天梯赛 L2-006 树的遍历(序列建树)
L2-006 树的遍历 (25 分) 给定一棵二叉树的后序遍历和中序遍历,请你输出其层序遍历的序列.这里假设键值都是互不相等的正整数. 输入格式: 输入第一行给出一个正整数N(≤30),是二叉树中结点 ...
- MacBook Pro (13 英寸, 2012 年中)安装win7系统
准备: windows7 ISO镜像 16G或更大U盘(提前备份,需要格式化) Apple 官方提供的 windows7驱动程序 详细步骤: 1.打开Bootcamp,选择前两个选择点击继续,选择下载 ...