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 ...
随机推荐
- C#windows向窗体传递泛型类
修改窗体代码文件*.cs public partial class FormName<T> : Form partial说明此类还有一半在另外的cs文件中,正是系统替你写好的*.desig ...
- smbsh - 允许用UNIX命令访问NT文件系统
总览 smbsh 描述 此程序是Samba套件的一部分. smbsh允许你用UNIX命令诸如ls,egrep和rcp等来访问NT文件系统.必须用动态链接的shell以便使smbsh工作正常. 从命令提 ...
- django post get
GET请求和POST请求 GET请求: 1. 浏览器请求一个页面 2. 搜索引擎检索关键字的时候 POST请求: 1. 浏览器向服务端提交数据,比如登录/注册等 判断提交方式: if request. ...
- squid代理与缓存(上)
squid代理与缓存(上) 1. Squid介绍 1.1 缓存服务器介绍 缓存服务器(英文意思cache server),即用来存储(介质为内存及硬盘)用户访问的网页,图片,文件等等信息的专用服务器. ...
- 用Matlab的.m脚本文件处理实验室数据
找到相应的文件 findfile %1 打开文件夹 %2 拷贝第一个文件 %3 关闭当前文件,再次拷贝新的文件,直到文件末尾结束 clc clear DST_PATH_t = 'C:\Users\Ma ...
- BZOJ4710 [Jsoi2011]分特产 容斥
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=4710 题解 本来想去找一个二项式反演的题的,结果被 https://www.cnblogs.c ...
- 如何在Ubuntu 18.04上安装Apache Web服务器
一. apt库安装 1.在终端输入更新检查命令,sudo apt-get update 2. 在更新完成后(如果不想检查更新,也可直接输入此步)输入:sudo apt-get install apac ...
- 【leetcode】892. Surface Area of 3D Shapes
题目如下: 解题思路:对于v = grid[i][j],其表面积为s = 2 + v*4 .接下来只要在判断其相邻四个方向有没有放置立方体,有的话减去重合的面积即可. 代码如下: class Solu ...
- Linux 多个cpp文件的编译(Makefile)
打包so文件: CC = g++ CFLAGS=-Wall -O2 -fPIC TARGET = libbg.so SRCS := $(wildcard *.cpp) OBJS := $(patsub ...
- pycharm 进入Pythonshell脚本调试