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. axios 利用new FileReader() 下载文件获取返回的错误信息

    this.axios({           method: "post",           url: url,           data: data,           ...

  2. CSS语法规则

    一.At-rule 一种以@开头的声明语句,以分号;结尾.语法规则为: @IDENTIFIER (RULE); . At-rule主要用作表示CSS的行为,参考: https://www.cnblog ...

  3. RabbitMQ ——整体架构

    一 .概述 从整体上讲Rabbitmq就是一个生产者消费者的模型. 我们将中间的整个broker就当做是一个消息中间件的实体就可以了. 单从这个方面上讲,生产者发送消息到broker上面,然后消费者从 ...

  4. 阿里云搭建香港代理服务器 shadownsocks

    阿里云香港代理服务器搭建方式: 1.阿里云官网购买轻量级服务器即可,流量,配置套餐自己选择,CENTOS7,进入控制台后打开端口管理列表,打开9000即可. 2.安装shadownsocks服务端: ...

  5. ini配置文件内如果有更新参数

    ini配置文件内如果有更新参数 执行更新 更新参数 自动去下载执行????

  6. 【LeetCode】回溯法 backtracking(共39题)

    [10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses ( ...

  7. HTML基础 有序列表写个人收藏夹

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  8. elasticsearch相关聚合查询示例

    索引(index):logstash-nginx-*,type:nginx_access 请求路径: 1.按照某个字段进行分组统计访问量 { "query": { "bo ...

  9. GSL+DevC++使用

    在DEV C++中配置GSL1.8库 前面写了如何在vs2005中添加gsl,本文所所述为在dev c++中使用gsl库,由实践总结而得. 准备软件: 1.Orwell Dev C++ 5.6.2 N ...

  10. 【CF1257A】Two Rival Students【思维】

    题意:给你n个人和两个尖子生a,b,你可以操作k次,每次操作交换相邻两个人的位置,求问操作k次以内使得ab两人距离最远是多少 题解:贪心尽可能的将两人往两边移动,总结一下就是min(n-1,|a-b| ...