hdu2732 Leapin' Lizards 最大流+拆点
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 最大流+拆点的更多相关文章
- HDU2732 Leapin' Lizards —— 最大流、拆点
题目链接:https://vjudge.net/problem/HDU-2732 Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu 2732 Leapin' Lizards 最大流 拆点 建图
题目链接 题意 给定一张网格,格子中有些地方有柱子,有些柱子上面有蜥蜴. 每个柱子只能承受有限只蜥蜴从上面经过.每只蜥蜴每次能走到相距曼哈顿距离\(\leq k\)的格子中去. 问有多少只蜥蜴能走出网 ...
- hdu 2732 Leapin' Lizards (最大流 拆点建图)
Problem Description Your platoon of wandering lizards has entered a strange room in the labyrinth yo ...
- HDU2732 Leapin' Lizards 最大流
题目 题意: t组输入,然后地图有n行m列,且n,m<=20.有一个最大跳跃距离d.后面输入一个n行的地图,每一个位置有一个值,代表这个位置的柱子可以经过多少个猴子.之后再输入一个地图'L'代表 ...
- hdu2732 Leapin' Lizards (网络流dinic)
D - Leapin' Lizards Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU2732 Leapin' Lizards
Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- HDU2732 Leapin' Lizards 网络流 最大流 SAP
原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...
- HDU-2732-leapin'Lizards(最大流, 拆点)
链接: https://vjudge.net/problem/HDU-2732 题意: Your platoon of wandering lizards has entered a strange ...
- HDU2732:Leapin' Lizards(最大流)
Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
随机推荐
- isScroll 插件在iPhone 5s 和以上版本
才加入这个移动项目组三天,解决一个同事(请假),解决一个切换头部tab 选型时,下拉数据,再次切换到另外一个选项时,出现滚动条距离顶部有些距离,当频繁操作会出现距离顶部距离加大问题(第二天衍生出其他b ...
- OO第三次课程总结分析
OO第三次课程总结分析 规格化设计发展历史 在网上找了好久也没找到合适的信息,稍稍参考了同学的博客.大致如下:最初的的软件并没有形式化方法,随着软件工程的兴起,为了便于工程间的协调管理,人们提出采用工 ...
- 每天CSS学习之text-indent
text-indent是CSS的一个属性,其作用是定义首行文本的缩进.其值如下: 1.length:首行缩进固定的长度.默认值为0. 设置 首行缩进2em的长度. div{ width:300px; ...
- redis、memcached、mongoDB 对比
Mongodb和Memcached不是一个范畴内的东西.Mongodb是文档型的非关系型数据库,其优势在于查询功能比较强大,能存储海量数据.Mongodb 和 Memcached不存在谁替换谁的问题. ...
- 前端之Bootstrap框架
一.Bootstrap介绍 Bootstrap是Twitter开源的基于HTML.CSS.JavaScript的前端框架. 它是为实现快速开发Web应用程序而设计的一套前端工具包. 它支持响应式布局, ...
- Cracking The Coding Interview 9.3
//Given a sorted array of n integers that has been rotated an unknown number of times, give an O(log ...
- Android : SELinux 简析&修改
一 SELinux背景知识 SELinux出现之前,Linux上的安全模型叫DAC,全称是Discretionary Access Control,翻译为自主访问控制.DAC的核心思想很简单,就是: ...
- C++基础知识:类的静态成员
1.普通成员变量通过对象名能够访问public成员变量每个对象都可以有只属于自己的成员变量成员变量不能在对象之间共享 2.从命名空间的角度:类的静态成员只是类这个命名空间中的全局变量和全局函数不同之处 ...
- 2.13 C++拷贝构造函数
参考:http://www.weixueyuan.net/view/6344.html 总结: 如果拷贝构造函数的参数不是对象的引用,则是不允许的.如 book(book b); 是无法编译通过的. ...
- SharePoint Framework 企业向导(八)
博客地址:http://blog.csdn.net/FoxDave 构建关于SPFx自定义的计划 在SPFx引入的时候,你就需要对它进行规划了.规划要从介绍SPFx解决方案使用的新的技术栈开始.开 ...