HDU2732 Leapin' Lizards
Leapin' Lizards
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1268 Accepted Submission(s): 530
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.
always 1 ≤ d ≤ 3.
#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的更多相关文章
- HDU2732 Leapin' Lizards —— 最大流、拆点
题目链接:https://vjudge.net/problem/HDU-2732 Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) M ...
- hdu2732 Leapin' Lizards (网络流dinic)
D - Leapin' Lizards Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- HDU2732 Leapin' Lizards 网络流 最大流 SAP
原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...
- hdu2732 Leapin' Lizards 最大流+拆点
Your platoon of wandering lizards has entered a strange room in the labyrinth you are exploring. As ...
- HDU2732 Leapin' Lizards 最大流
题目 题意: t组输入,然后地图有n行m列,且n,m<=20.有一个最大跳跃距离d.后面输入一个n行的地图,每一个位置有一个值,代表这个位置的柱子可以经过多少个猴子.之后再输入一个地图'L'代表 ...
- HDU2732:Leapin' Lizards(最大流)
Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
- Leapin' Lizards
Leapin' Lizards 题目大意: 在一个网格地图中有一些高度不同的石柱,一些石柱上站着一些蜥蜴,你的任务是让尽量多的蜥蜴逃到边界外. 每行每列中相邻石柱的距离为1,蜥蜴的跳跃距离是d,即蜥蜴 ...
- Leapin' Lizards(经典建图,最大流)
Leapin' Lizards http://acm.hdu.edu.cn/showproblem.php?pid=2732 Time Limit: 2000/1000 MS (Java/Others ...
随机推荐
- 20180209-shutil模块
下面讲解shutil模块的相关操作: 1.shutil.copyfileobj(fsrc, fdst, length=16*1024) 将fsrc文件内容拷贝到fdst文件中,length是指一次拷贝 ...
- Xcode 及 iOS 常用宏和常量
Xcode Xcode 工程设置支持 bash 脚本及其语法,如 $(PROJECT_DIR)$(PROJECT_DIR) PROJECT_DIR 代表当前工程的绝对路径,所以 $(PROJECT_D ...
- Java中的关键字--synchronized
在并发编程中,synchronized关键字是常出现的角色.之前我们都称呼synchronized关键字为重量锁,但是在JDK1.6中对synchronized进行了优化,引入了偏向锁.轻量锁.本篇介 ...
- shell函数的结束与返回值
- (ACM模板)二元组pair
#include<iostream> #include<cstdio> #include<utility> using namespace std; typedef ...
- RPC_简洁版
1.定义服务接口 public interface RpcService { int printHello(int msg); } 2.定义服务接口实现类 public class RpcInterf ...
- Celery与Django的结合
一.什么是Celery Celery 是一个 基于python开发的分布式异步消息任务队列,通过它可以实现任务的异步处理以及定时任务的处理,它的基本工作流程是: 先启动任务执行单元Worker,让它一 ...
- UVA10779 Collectors Problem 【迁移自洛谷博客】
这是一道不错的练最大流建模的基础题. 这种题目审题是关键. Bob's friends will only exchange stickers with Bob, and they will give ...
- leetcode之删除数组中的重复值(26题)
给定一个排序数组,你需要在原地删除重复出现的元素,使得每个元素只出现一次,返回移除后数组的新长度. 不要使用额外的数组空间,你必须在原地修改输入数组并在使用 O(1) 额外空间的条件下完成. 示例 1 ...
- C#-弄懂泛型和协变、逆变
脑图概览 泛型声明和使用 协变和逆变 <C#权威指南>上在委托篇中这样定义: 协变:委托方法的返回值类型直接或者间接地继承自委托前面的返回值类型; 逆变:委托签名中的参数类型继承自委托方法 ...