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 ...
随机推荐
- javascript void函数
<a href="javascript:doTest2();void(0);">here</a> 但这儿的void(0)究竟是何含义呢? Javascrip ...
- 关于静态资源是否应该放到WEB-INF目录
首先,css/js/html没有必要放在WEB-INF下. 最终这些会被原封不动的展现在客户端,所以访问安全根本就不会成为问题. jsp放在web-inf下,原因主要有两个 远古时代的模式会把业务逻辑 ...
- jvm常用参数
-Xms512m:初始堆内存 -Xmx512m:最大堆内存 -XX:PermSize=256m:初始永久代内存(方法区,非堆) -XX:MaxPermSize=256m:最大永久代内存(方法区,非堆) ...
- CSS(三)--自定义标签
HTML代码 <body> <ul> <li>1</li> <li>2</li> </ul> </body&g ...
- CMOS集成门电路
CMOS集成门电路:mos管构成的集成门电路 CMOS:互补对称金属氧化物半导体器件 CMOS反相器电路是由N沟道MOSFET和P沟道MOSFET互补而成:特点静态功耗近视为0,电源电压可在很宽的范围 ...
- nginx启用php
1. php下载https://secure.php.net/downloads.php搜索china镜像站点,从这里下载http://cn2.php.net/get/php-7.2.3.tar.gz ...
- C++面向对象实现封装线程池
body, table{font-family: 微软雅黑; font-size: 13.5pt} table{border-collapse: collapse; border: solid gra ...
- 第三篇 功能实现(1) (Android学习笔记)
第三篇 功能实现(1) 第8章 Android应用程序组成 ●Android的一些中.底层基础知识 ※ Android Framework 启动过程 Android手机系统本质上是一个基于Linux的 ...
- 创建自己的docker基础镜像
1.下载镜像 centos7 docker pull centos: 2.创建容器加载镜像 docker run -i -t --name centos7 centos: docker run 参数详 ...
- 强化学习6-MC与TD的比较-实战
# encoding:utf-8 import numpy as np import matplotlib.pylab as plt ''' 随机行走问题 0 - 1 - 2 - 3 - 4 - 5 ...