Your platoon of wandering lizards has entered a strange room in the labyrinth you are exploring. As you are looking around for hidden treasures, one of the rookies steps on an innocent-looking stone and the room's floor suddenly disappears! Each lizard in your platoon is left standing on a fragile-looking pillar, and a fire begins to rage below... Leave no lizard behind! Get as many lizards as possible out of the room, and report the number of casualties.
The pillars in the room are aligned as a grid, with each pillar one unit away from the pillars to its east, west, north and south. Pillars at the edge of the grid are one unit away from the edge of the room (safety). Not all pillars necessarily have a lizard. A lizard is able to leap onto any unoccupied pillar that is within d units of his current one. A lizard standing on a pillar within leaping distance of the edge of the room may always leap to safety... but there's a catch: each pillar becomes weakened after each jump, and will soon collapse and no longer be usable by other lizards. Leaping onto a pillar does not cause it to weaken or collapse; only leaping off of it causes it to weaken and eventually collapse. Only one lizard may be on a pillar at any given time.

题意:在网格内有若干只蜥蜴,他们每次可以跳k长度的网格,每个格子在被一只蜥蜴踩过之后就会崩塌,问有多少蜥蜴不能离开网格。

每个格子向它能跳到的格子建边,外圈格子向超级汇点建边,通过将网格拆成入点和出点限制通过的蜥蜴数量,直接跑网络流就可以了。

 #include<stdio.h>
#include<string.h>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxm=;
const int INF=0x7fffffff; struct edge{
int from,to,f;
edge(int a,int b,int c):from(a),to(b),f(c){}
}; struct dinic{
int s,t,m;
vector<edge>e;
vector<int>g[maxm];
bool vis[maxm];
int cur[maxm],d[maxm]; void init(int n){
for(int i=;i<=n;i++)g[i].clear();
e.clear();
} void add(int a,int b,int c){
e.push_back(edge(a,b,c));
e.push_back(edge(b,a,));
m=e.size();
g[a].push_back(m-);
g[b].push_back(m-);
} bool bfs(){
memset(vis,,sizeof(vis));
queue<int>q;
q.push(s);
vis[s]=;
d[s]=;
while(!q.empty()){
int u=q.front();
q.pop();
for(int i=;i<g[u].size();i++){
edge tmp=e[g[u][i]];
if(!vis[tmp.to]&&tmp.f>){
d[tmp.to]=d[u]+;
vis[tmp.to]=;
q.push(tmp.to);
}
}
}
return vis[t];
} int dfs(int x,int a){
if(x==t||a==)return a;
int flow=,f;
for(int& i=cur[x];i<g[x].size();i++){
edge& tmp=e[g[x][i]];
if(d[tmp.to]==d[x]+&&tmp.f>){
f=dfs(tmp.to,min(a,tmp.f));
tmp.f-=f;
e[g[x][i]^].f+=f;
flow+=f;
a-=f;
if(a==)break;
}
}
if(flow==)d[x]=-;
return flow;
} int mf(int s,int t){
this->s=s;
this->t=t;
int flow=;
while(bfs()){
memset(cur,,sizeof(cur));
flow+=dfs(s,INF);
}
return flow;
}
}; char a[][],b[][];
struct point{
int x,y,n;
}p[]; int aabs(int a){
return a>=?a:-a;
} int main(){
int T;
scanf("%d",&T);
for(int q=;q<=T;q++){
int i,j;
int n,m,k;
scanf("%d%d",&n,&k);
for(i=;i<=n;i++){
scanf("%s",a[i]+);
}
for(i=;i<=n;i++){
scanf("%s",b[i]+);
}
m=strlen(a[]+);
dinic d;
d.init(n*m*+);
int cnt=,l,c=;
for(i=;i<=n;i++){
for(j=;j<=m;j++){
if(a[i][j]!=''){
int tmp=(i-)*m+j;
d.add(tmp,tmp+m*n,a[i][j]-'');
for(l=;l<=cnt;l++){
if(aabs(i-p[l].x)+aabs(j-p[l].y)<=k){
d.add(tmp+m*n,p[l].n,INF);
d.add(p[l].n+n*m,tmp,INF);
}
}
cnt++;
p[cnt].x=i;
p[cnt].y=j;
p[cnt].n=tmp;
if(b[i][j]=='L'){
c++;
d.add(,tmp,);
}
if(i<=k||j<=k||n-i+<=k||m-j+<=k)d.add(tmp+n*m,n*m*+,INF);
}
}
}
int ans=c-d.mf(,*n*m+);
printf("Case #%d: ",q);
if(ans)printf("%d",ans);
else printf("no");
if(ans<=)printf(" lizard was left behind.\n");
else printf(" lizards were left behind.\n");
}
return ;
}

hdu2732 Leapin' Lizards 最大流+拆点的更多相关文章

  1. HDU2732 Leapin' Lizards —— 最大流、拆点

    题目链接:https://vjudge.net/problem/HDU-2732 Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    M ...

  2. hdu 2732 Leapin' Lizards 最大流 拆点 建图

    题目链接 题意 给定一张网格,格子中有些地方有柱子,有些柱子上面有蜥蜴. 每个柱子只能承受有限只蜥蜴从上面经过.每只蜥蜴每次能走到相距曼哈顿距离\(\leq k\)的格子中去. 问有多少只蜥蜴能走出网 ...

  3. hdu 2732 Leapin' Lizards (最大流 拆点建图)

    Problem Description Your platoon of wandering lizards has entered a strange room in the labyrinth yo ...

  4. HDU2732 Leapin' Lizards 最大流

    题目 题意: t组输入,然后地图有n行m列,且n,m<=20.有一个最大跳跃距离d.后面输入一个n行的地图,每一个位置有一个值,代表这个位置的柱子可以经过多少个猴子.之后再输入一个地图'L'代表 ...

  5. hdu2732 Leapin' Lizards (网络流dinic)

    D - Leapin' Lizards Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u ...

  6. HDU2732 Leapin' Lizards

    Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU2732 Leapin' Lizards 网络流 最大流 SAP

    原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...

  8. HDU-2732-leapin'Lizards(最大流, 拆点)

    链接: https://vjudge.net/problem/HDU-2732 题意: Your platoon of wandering lizards has entered a strange ...

  9. HDU2732:Leapin' Lizards(最大流)

    Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

随机推荐

  1. 尚学堂java答案解析 第一章

    本答案为本人个人编辑,仅供参考,如果读者发现,请私信本人或在下方评论,提醒本人修改 一.选择题: 1.C 解析:java为了安全,中并没有引入C语言的指针概念. 2.AD 解析:B:Java先通过ja ...

  2. git-github-TortoiseGit综合使用教程(一)简介

    简介: 本系列教程将参考廖雪峰的git系列教程,使用github的web界面,和TortoiseGit图形界面windows程序来实现. git 是什么: Git是目前世界上最先进的分布式版本控制系统 ...

  3. UNICODE_STRING(用户模式 内核模式)

    UNICODE_STRING结构: typedef struct  _UNICODE_STRING { USHORT Length;                                   ...

  4. Android开发 ---Activity的7种运行状态

     Android开发 ---Activity的7种运行状态 创建 --> 启动 --> 运行 -->  暂停 --> 停止 --> 销毁 重启 操作图解: 1.MainA ...

  5. SharePoint REST API - 确定REST端点URL

    博客地址:http://blog.csdn.net/FoxDave SharePoint REST端点URI的结构 在你能够通过REST访问SharePoint资源之前,首先你要做的就是找出对应的 ...

  6. day73 母版 中间件

    关于母版自定义的问题 模板引擎: 基本实用{{k1}}  if  for  在页面传参数 并判断  通过母版进行交互 一 模板中自定义函数:操作步骤 1在已经注册的App中创建一个名字叫templat ...

  7. 『翻译』Android USB Host

    USB Host When your Android-powered device is in USB host mode, it acts as the USB host, powers the b ...

  8. Python写一个批量生成账号的函数

    批量生成账户信息,产生的账户由@sina.com结尾,长度由用户输入,产生多少条也由用户输入,用户名不能重复,用户名必须由大写字母.小写字母和数字组成. def Users(num,len): # n ...

  9. Github笔记(1)

    学习目的: 借助GitHub托管项目代码 GitHub官方介绍: 中文:http://www.cnblogs.com/twtp/articles/5264073.html 英文:https://gui ...

  10. perror strerror使用方法

    1. 简介 很多系统函数在错误返回时将错误原因记录在libc定义的全局变量errno中,每种错误原因对应一个错误码. errno在头文件errno.h中声明,是一个整型变量,所有错误码都是正整数.然后 ...