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 ...
随机推荐
- axios 利用new FileReader() 下载文件获取返回的错误信息
this.axios({ method: "post", url: url, data: data, ...
- CSS语法规则
一.At-rule 一种以@开头的声明语句,以分号;结尾.语法规则为: @IDENTIFIER (RULE); . At-rule主要用作表示CSS的行为,参考: https://www.cnblog ...
- RabbitMQ ——整体架构
一 .概述 从整体上讲Rabbitmq就是一个生产者消费者的模型. 我们将中间的整个broker就当做是一个消息中间件的实体就可以了. 单从这个方面上讲,生产者发送消息到broker上面,然后消费者从 ...
- 阿里云搭建香港代理服务器 shadownsocks
阿里云香港代理服务器搭建方式: 1.阿里云官网购买轻量级服务器即可,流量,配置套餐自己选择,CENTOS7,进入控制台后打开端口管理列表,打开9000即可. 2.安装shadownsocks服务端: ...
- ini配置文件内如果有更新参数
ini配置文件内如果有更新参数 执行更新 更新参数 自动去下载执行????
- 【LeetCode】回溯法 backtracking(共39题)
[10]Regular Expression Matching [17]Letter Combinations of a Phone Number [22]Generate Parentheses ( ...
- HTML基础 有序列表写个人收藏夹
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- elasticsearch相关聚合查询示例
索引(index):logstash-nginx-*,type:nginx_access 请求路径: 1.按照某个字段进行分组统计访问量 { "query": { "bo ...
- GSL+DevC++使用
在DEV C++中配置GSL1.8库 前面写了如何在vs2005中添加gsl,本文所所述为在dev c++中使用gsl库,由实践总结而得. 准备软件: 1.Orwell Dev C++ 5.6.2 N ...
- 【CF1257A】Two Rival Students【思维】
题意:给你n个人和两个尖子生a,b,你可以操作k次,每次操作交换相邻两个人的位置,求问操作k次以内使得ab两人距离最远是多少 题解:贪心尽可能的将两人往两边移动,总结一下就是min(n-1,|a-b| ...