Leapin' Lizards

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1268    Accepted Submission(s): 530

Problem Description
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.
 
Input
The input file will begin with a line containing a single integer representing the number of test cases, which is at most 25. Each test case will begin with a line containing a single positive integer n representing the number of rows in the map, followed by a single non-negative integer d representing the maximum leaping distance for the lizards. Two maps will follow, each as a map of characters with one row per line. The first map will contain a digit (0-3) in each position representing the number of jumps the pillar in that position will sustain before collapsing (0 means there is no pillar there). The second map will follow, with an 'L' for every position where a lizard is on the pillar and a '.' for every empty pillar. There will never be a lizard on a position where there is no pillar.Each input map is guaranteed to be a rectangle of size n x m, where 1 ≤ n ≤ 20 and 1 ≤ m ≤ 20. The leaping distance is
always 1 ≤ d ≤ 3.
 
Output
For each input case, print a single line containing the number of lizards that could not escape. The format should follow the samples provided below.
 
Sample Input
4
3 1
1111
1111
1111
LLLL
LLLL
LLLL
3 2
00000
01110
00000
.....
.LLL.
.....
3 1
00000
01110
00000
.....
.LLL.
.....
5 2
00000000
02000000
00321100
02000000
00000000
........
........
..LLLL..
........
........
 
Sample Output
Case #1: 2 lizards were left behind.
Case #2: no lizard was left behind.
Case #3: 3 lizards were left behind.
Case #4: 1 lizard was left behind.
 

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue> using namespace std;
const int INF = 1e9 ;
const int N = ;
const int M = ; bool vis[N];
int eh[N],et[M],nxt[M],ef[M],ec[M],etot;
int s , t , n , m;
int d[N],cur[N];
char mp1[N][N] , mp2[N][N];
int colum; struct node
{
int s,e,p; }ma[M]; void init(){
memset( eh, - , sizeof eh) ;
etot = ;
} void addedge( int u , int v , int c ){
et[etot] = v ; nxt[etot] = eh[u]; ef[etot] = ; ec[etot] = c ; eh[u] = etot++;
et[etot] = u ; nxt[etot] = eh[v]; ef[etot] = ; ec[etot] = ; eh[v] = etot++;
} bool bfs ()
{
memset( vis , , sizeof vis);
queue< int >que;
que.push(s) ;
d[s] = ;
vis[s] = ;
while( !que.empty() ) {
int u = que.front(); que.pop();
for( int i = eh[ u ] ; ~i ; i = nxt[i] ){
int v = et[i] , c = ec[i] , f = ef[i];
if( !vis[v] && c > f){
vis[v] = ;
d[v] = d[u] + ;
que.push(v);
}
}
}
return vis[t];
} int dfs (int x ,int a)
{
if ( x == t || a == ){
return a ;
}
int flow = , F;
for( int &i = cur[x] ; ~i ; i = nxt[i] ){
int v = et[i] , c = ec[i] , &f = ef[i];
if( d[x] + == d[v] && ( F = dfs (v, min( a, c - f))) > ) {
f += F;
ef[ i ^ ] -= F;
flow += F;
a -= F;
if( a == )break;
}
}
return flow;
} int MF(){
int flow = ;
while( bfs() ){
memcpy( cur , eh , sizeof eh );
flow += dfs(s , INF);
}
return flow;
}
bool check(int x ,int y){
if( x - m < || x + m >= n )return ;
if( y - m < || y + m >= colum )return ;
return ;
} void run()
{
init();
s = N - , t = N - ;
scanf("%d%d",&n,&m);
int cnt = ; for(int i = ; i < n ;++i ){scanf("%s",mp1[i]);}
for(int i = ; i < n ;++i ){scanf("%s",mp2[i]);}
colum = strlen(mp1[]);
for(int i = ; i < n ;++i ){
for( int j = ; j < colum ; ++j )
mp1[i][j] -= '';
} for(int i = ; i < n ;++i ){
for( int j = ; j < colum ; ++j ){
if( mp1[i][j] > ){ addedge( i * colum + j , i * colum + j + colum * n , mp1[i][j] ); if( check( i, j ) ){
addedge( i*colum +j + colum * n , t,INF );
} for(int ii = i - m ; ii <= i+m ;++ii ){
for(int jj = j - m ; jj <= j+m ;++jj ){
if( abs(i-ii) + abs(j-jj) <= m && mp1[i][j] > ){
addedge( ii * colum + jj + colum * n ,i * colum + j , INF );
}
}
}
} if(mp2[i][j]=='L'){
cnt ++ ;
addedge(s, i*colum+j , );
}
}
} int ans = MF();
ans = cnt - ans ; if(!ans )
cout <<"no lizard was left behind."<<endl;
else if(ans == )
cout <<"1 lizard was left behind."<<endl;
else
cout<<ans<<" lizards were left behind."<<endl; } int main()
{
#ifdef LOCAL
freopen("in.txt","r",stdin);
#endif // LOCAL int _ , cas = ;
scanf("%d",&_);
while(_--){
printf("Case #%d: ",cas++);
run();
}
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. hdu2732 Leapin' Lizards (网络流dinic)

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

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

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

  4. hdu2732 Leapin' Lizards 最大流+拆点

    Your platoon of wandering lizards has entered a strange room in the labyrinth you are exploring. As ...

  5. HDU2732 Leapin' Lizards 最大流

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

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

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

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

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

  8. Leapin' Lizards

    Leapin' Lizards 题目大意: 在一个网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴 ...

  9. Leapin' Lizards(经典建图,最大流)

    Leapin' Lizards http://acm.hdu.edu.cn/showproblem.php?pid=2732 Time Limit: 2000/1000 MS (Java/Others ...

随机推荐

  1. 攻防世界--dmd-50

    测试文件:https://adworld.xctf.org.cn/media/task/attachments/7ef7678559ea46cbb535c0b6835f2f4d 1.准备 获取信息 6 ...

  2. Mata标签,og标签

    一.Mata标签 meta是用来在HTML文档中模拟HTTP协议的响应头报文,meta 标签用于网页的<head>与</head>中.meta 的属性有两种:name和http ...

  3. 一、WebApi模型验证

    一.新建项目 选择空的项目webapi 查看启动端口 创建控制器 添加方法 public class VerifController : ApiController { public IHttpAct ...

  4. 2017ICPC沈阳赛现场赛 L-Tree (dfs)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6228 题目大意:给一棵树,需要用k种颜色给树上的节点染色,问你在最优的染色方案下,相同颜色的节点连接的 ...

  5. Java虚拟机(JVM)与垃圾回收机制(GC)的详解

    一.JVM结构 根据<java虚拟机规范>规定,JVM的基本结构一般如下图所示: 从左图可知,JVM主要包括四个部分: 1.类加载器(ClassLoader):在JVM启动时或者在类运行时 ...

  6. Sass-Opacity函数-rgba()函数

    在前面介绍 RGB 函数一节中,还记得吗?有一个 rgba() 函数可以创建一个颜色,同时还可以对颜色修改其透明度.其可以接受两个参数,第一个参数为颜色,第二个参数是你需要设置的颜色透明值. > ...

  7. Sass-unitless()函数

    unitless() 函数相对来说简单明了些,只是用来判断一个值是否带有单位,如果不带单位返回的值为 true,带单位返回的值为 false: >> unitless(100) true ...

  8. 数据库与缓存:2.Redis数据库的基本知识

    1.属于什么类型的数据库 not only sql  非关系型数据库,与传统的关系型数据库不同,存储形式都是kv形式. 2.特点 几乎不支持事务,key-value形式存储,支持队列和缓存(可以设置数 ...

  9. SpringBoot JSON文件读取

    @Componentpublic class StepExecutor implements Runnable { @Value("classpath:menu.json") pr ...

  10. python每日练习

    """ 习题 1:一个列表,排重,不能用 set,也不能用字典 """ #方法一1:循环.遍历 l = [1,1,1,2,2,3,4,4,6 ...