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

# 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. 基于queryperf 和 perftcpdns 的DNS压力测试

    最近在AWS上安装了PPTP VPN 做代理,手机, pad 也可以无缝FQ,甚是开心.最近工作不太忙,研究一下缓存加速的调优.系统已经安装的nscd文件级的缓存和dnsmasq,cpu级的dns缓存 ...

  2. memcached 的实践操作

    memcached安装和使用   yum install -y libevent  memcached  libmemcached   启动命令:   /etc/init.d/memcached st ...

  3. ansible实践-1

      不需要安装客户端,通过sshd去通信 基于模块工作,模块可以由任何语言开发 不仅支持命令行使用模块,也支持编写yaml格式的playbook 支持sudo 有提供UI(浏览器图形化)www.ans ...

  4. css3渐变 transition使用方法

    <style> div{ width:300px; height:300px; background:#89F; margin:100px auto; transition:width 1 ...

  5. MySQL统计函数记录——按月、按季度、按日、时间段统计

    按年汇总,统计:select sum(mymoney) as totalmoney, count(*) as sheets from mytable group by date_format(col, ...

  6. [POJ 3581]Sequence

    [POJ 3581]Sequence 标签: 后缀数组 题目链接 题意 给你一串序列\(A_i\),保证对于$ \forall i \in [2,n],都有A_1 >A_i$. 现在需要把这个序 ...

  7. InputStream中通过mark和reset方法重复利用缓存

    通过缓存InputStream可重复利用一个InputStream,但是要缓存一整个InputStream内存压力可能是比较大的.如果第一次读取InputStream是用来判断文件流类型,文件编码等用 ...

  8. QWebSocket 客户端

    QWebSocket 客户端 Public Function - QWebSocket(const QString &origin = QString(),QWebSocketProtocol ...

  9. hihoCoder 1051 : 补提交卡 枚举

    思路:预处理cnt(i)表示前i个数中有多少天需要补提交卡,枚举各个连续区间,区间[j, i]中需要补提交卡的天数是cnt(i) - cnt(j-1),判断m是否大于等于cnt(i) - cnt(j- ...

  10. uva208

    一道简单的路径打印,首先需要一次dfs判断能否从1到达目标点,否则可能会超时.还有一点就是那个格式需要注意下,每条路径前没有空格(看起来好像有3个空格)-. AC代码: #include<cst ...