网络流
一个点拆成两个,注意要把某一类边连反过来
这样才能保证有限制

# include <bits/stdc++.h>
# define IL inline
# define RG register
# define Fill(a, b) memset(a, b, sizeof(a))
# define Copy(a, b) memcpy(a, b, sizeof(a))
# define ID(a, b) (a - 1) * c + b
# define Sqr(x) ((x) * (x))
# define Dis(i, j, x, y) (Sqr(i - x) + Sqr(j - y))
using namespace std;
typedef long long ll; const int _(1010), __(6e6 + 10), INF(2147483647); IL ll Read(){
RG char c = getchar(); RG ll x = 0, z = 1;
for(; c < '0' || c > '9'; c = getchar()) z = c == '-' ? -1 : 1;
for(; c >= '0' && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
return x * z;
} int num, r, c, d, high[21][21], w[__], fst[_], nxt[__], to[__], cnt, S, T, lev[_], cur[_], max_flow;
queue <int> Q; IL void Add(RG int u, RG int v, RG int f){
w[cnt] = f; to[cnt] = v; nxt[cnt] = fst[u]; fst[u] = cnt++;
w[cnt] = 0; to[cnt] = u; nxt[cnt] = fst[v]; fst[v] = cnt++;
} IL int Dfs(RG int u, RG int maxf){
if(u == T) return maxf;
RG int ret = 0;
for(RG int &e = cur[u]; e != -1; e = nxt[e]){
if(lev[to[e]] != lev[u] + 1 || !w[e]) continue;
RG int f = Dfs(to[e], min(w[e], maxf - ret));
ret += f; w[e ^ 1] += f; w[e] -= f;
if(ret == maxf) break;
}
if(!ret) lev[u] = 0;
return ret;
} IL bool Bfs(){
Fill(lev, 0); lev[S] = 1; Q.push(S);
while(!Q.empty()){
RG int u = Q.front(); Q.pop();
for(RG int e = fst[u]; e != -1; e = nxt[e]){
if(lev[to[e]] || !w[e]) continue;
lev[to[e]] = lev[u] + 1;
Q.push(to[e]);
}
}
return lev[T];
} int main(RG int argc, RG char* argv[]){
r = Read(); c = Read(); d = Read(); Fill(fst, -1); T = r * c * 2 + 1;
for(RG int i = 1; i <= r; ++i)
for(RG int j = 1; j <= c; ++j){
RG char cc; scanf(" %c", &cc);
high[i][j] = (cc ^ 48);
if(!high[i][j]) continue;
Add(ID(i, j), ID(i, j) + r * c, high[i][j]);
if(i <= d || j <= d || r - i < d || c - j < d) Add(ID(i, j) + r * c, T, INF);
}
for(RG int i = 1; i <= r; ++i)
for(RG int j = 1; j <= c; ++j){
RG char cc; scanf(" %c", &cc);
for(RG int x = 1; x <= r; ++x)
for(RG int y = 1; y <= c; ++y)
if((x != i || y != j) && high[x][y] && Dis(i, j, x, y) <= d * d)
Add(ID(i, j) + r * c, ID(x, y), INF);
if(cc != 'L') continue;
Add(S, ID(i, j), 1); num++;
}
while(Bfs()) Copy(cur, fst), max_flow += Dfs(S, INF);
printf("%d\n", num - max_flow);
return 0;
}

[SCOI2007]蜥蜴的更多相关文章

  1. 1066: [SCOI2007]蜥蜴

    1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3545  Solved: 1771[Submit][Status] ...

  2. BZOJ 1066 POJ 2711 [SCOI2007]蜥蜴

    与POJ 1815 Friendship类似,该题之前也做过 目前处于TLE状态.样例已经通过 1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec  Memory Limit:  ...

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

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

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

    结点容量..拆点然后随便写 --------------------------------------------------------------- #include<cstdio> ...

  5. P2472 [SCOI2007]蜥蜴(网络流)

    P2472 [SCOI2007]蜥蜴 把每个点拆成2个点,两点之间连边的边权为石柱高度 新建虚拟源点$S$和汇点$T$ $S$向所有有蜥蜴的点连边,边权1 其他边都连$inf$ 剩下就是裸的$dini ...

  6. POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)

    POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...

  7. P2472 [SCOI2007]蜥蜴(网络最大流)

    P2472 [SCOI2007]蜥蜴 题目描述 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距 ...

  8. 【bzoj1066】【luogu2472】[SCOI2007]蜥蜴

    1066: [SCOI2007]蜥蜴 Time Limit: 1 Sec  Memory Limit: 162 MB Description 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上 ...

  9. bzoj千题计划135:bzoj1066: [SCOI2007]蜥蜴

    http://www.lydsy.com/JudgeOnline/problem.php?id=1066 每个柱子拆成两个点 i<<1,i<<1|1,之间连流量为高度的边 如果 ...

  10. 题解 P2472 【[SCOI2007]蜥蜴】

    P2472 [SCOI2007]蜥蜴 题目背景 07四川省选 题目描述 在一个r行c列的网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱 ...

随机推荐

  1. Linux常用命令手册

    Linux常用命令手册 NO 分类 PS1 命令名 用法及参数 功能注解 对应章节 1 文件管理 # ls ls -a 列出当前目录下的所有文件,包括以.头的隐含文件     文件管理 # ls ls ...

  2. PHP实现WebService的简单示例和实现步骤

    首先我创建的文件有: api.php api的接口类文件 api.wsdl 我创建产生的最后要调用的接口文件 cometrue.php 注册service api类内容的所有内容的执行文件 creat ...

  3. laravel框架基础知识点

    一.数据库:DB    1.db查    DB::table('msg')->where('id','>',$id)->get()       查询单行    DB::table(' ...

  4. centos/linux下的安装Tomcat

    1.启动tomcat时候需要JDK依赖 如果没有安装的请移步到该链接Centos/linux下的JDK安装 2.从官网上下载tomcat压缩包 wget -c http://apache.fayea. ...

  5. ubuntu17.10 python3.6 install plugins for AI

    install order: tensorflow-gpu scikit-learn numpy scipy matplotlib tkinter tensorflow-gpu : pip insta ...

  6. CentOS常用命令搜集

    centos是32或者64位:getconf LONG_BIT

  7. basler 相机拍照简单类综合Emgu.CV---得到图档

    在网上找了半天都是下载要钱,自己试做了,经测试能ok,一起分享吧.给初学的人一点鼓励. using System;using System.Collections.Generic;using Syst ...

  8. 《android开发艺术探索》读书笔记(九)--四大组件

    接上篇<android开发艺术探索>读书笔记(八)--WindowManager No1: 四大组件除了BroadcastReceiver,其他三种组件都必须在AndroidManifes ...

  9. 《清华梦的粉碎》by王垠

     清华梦的诞生 小时候,妈妈给我一个梦.她指着一个大哥哥的照片对我说,这是爸爸的学生,他考上了清华大学,他是我们中学的骄傲.长大后,你也要进入清华大学读书,为我们家争光.我不知道清华是什么样子,但是我 ...

  10. PHPstudy端口占用的问题

    phpStudy很多同学下好了 用localhost可能不能读取到WWW目录下的文件,这个是因为端口被占用,打开其他选项菜单 =>打开配置文件=>httpd-conf=>修改端口号如 ...