HDU2732 最大流
Leapin' Lizards |
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 16 Accepted Submission(s): 7 |
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 |
Sample Output
Case #1: 2 lizards were left behind. |
Source
Mid-Central USA 2005
|
题意:
有n行的数字地图和字符地图,一只青蛙每次最多跳k单位长度,数字地图中的数字表示改点可以经过的次数,字符地图中L表示几只青蛙的初始位置,问有多少只青蛙跳不出地图。
注意这里的距离是abs(行号之差)+abs(列号之差)
代码:
//源点S编号0,网格的每个格子分成两个点i和i+n*m(n和m为网格的行和列数,其实i编号点是
//表示蜥蜴进来,而i+n*m编号的点是表示蜥蜴出去).汇点t编号n*m*2+1.如果格子i上有蜥蜴,
//那么从s到i有边(s,i,1).如果格子i能承受x次跳出,那么有边(i,i+n*m,x)如果从格子i能直
//接跳出网格边界,那么有边(i+n*m,t,inf)如果从格子i不能直接跳出网格,那么从i到离i距离
//<=d的网格j有边(i+n*m,j,inf).
//最终我们求出的最大流就是能跳出网格的蜥蜴数.include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<cmath>
using namespace std;
const int INF=0x7fffffff;
const int MAXN=;
const int MAXM=;
int S,T,tot,head[MAXN+],h[MAXN+];
char mp[][];
int Abs(int x) { return x>=?x:-x; }
struct Edge
{
int to,next,w;
}edge[MAXM+];
void addedge(int x,int y,int z)
{
edge[tot].to=y;
edge[tot].w=z;
edge[tot].next=head[x];
head[x]=tot++;
edge[tot].to=x;
edge[tot].w=;
edge[tot].next=head[y];
head[y]=tot++;
}
void init(int x)
{
S=;T=x;
tot=;
memset(head,-,sizeof(head));
}
bool bfs()
{
queue<int>q;
memset(h,-,sizeof(h));
q.push(S);
h[S]=;
while(!q.empty()){
int u=q.front();q.pop();
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(edge[i].w&&h[v]<){
q.push(v);
h[v]=h[u]+;
}
}
}
if(h[T]==-) return ;
return ;
}
int dfs(int u,int f)
{
if(u==T) return f;
int x,used=;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(edge[i].w&&h[v]==h[u]+){
x=f-used;
x=dfs(v,min(x,edge[i].w));
edge[i].w-=x;
edge[i^].w+=x;
used+=x;
if(used==f) return f;
}
}
if(!used) h[u]=-;
return used;
}
int dinic()
{
int ans=;
while(bfs())
ans+=dfs(S,INF);
return ans;
}
int main()
{
int n,m,d;
scanf("%d%d%d",&n,&m,&d);
init(n*m*+);
for(int i=;i<n;i++)
scanf("%s",mp[i]);
for(int i=;i<n;i++){
for(int j=;j<m;j++){
if(mp[i][j]=='') continue;
addedge(i*m+j+,i*m+j++n*m,mp[i][j]-'');
if(i+<=d||j+<=d||n-i<=d||m-j<=d) addedge(i*m+j++n*m,T,INF);
else{
for(int k=;k<n;k++){
for(int h=;h<m;h++){
if(mp[k][h]=='') continue;
if(i==k&&j==h) continue;
if(Abs(i-k)+Abs(j-h)<=d)
addedge(i*m+j++n*m,k*m+h+,INF); }
}
}
}
}
int sum=;
for(int i=;i<n;i++){
scanf("%s",mp[i]);
for(int j=;j<m;j++){
if(mp[i][j]=='L'){
sum++;
addedge(S,i*m+j+,);
}
}
}
printf("%d\n",sum-dinic());
return ;
}
HDU2732 最大流的更多相关文章
- hdu2732 最大流+拆点
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2732 题目给定一个场景,有n*m个方格,每个方格代表一个柱子,一个柱子可以承受不同次数的跳跃,开始时图 ...
- HDU2732 Leapin' Lizards 网络流 最大流 SAP
原文链接http://www.cnblogs.com/zhouzhendong/p/8362002.html 题目传送门 - HDU2732 题意概括 给你一个网格,网格上的一些位置上有一只蜥蜴,所有 ...
- HDU2732 Leapin' Lizards —— 最大流、拆点
题目链接:https://vjudge.net/problem/HDU-2732 Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU2732:Leapin' Lizards(最大流)
Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu2732 Leapin' Lizards 最大流+拆点
Your platoon of wandering lizards has entered a strange room in the labyrinth you are exploring. As ...
- HDU2732(KB11-K 最大流)
Leapin' Lizards Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 最大流拆点——hdu2732,poj3436
一种很普遍的做法就是把一个带有容量的点拆成两个点,一个入点一个出点,链接两个点的边的权值为这个点的容量 hdu3732 #include<cstdio> #include<cstri ...
- HDU2732 Leapin' Lizards 最大流
题目 题意: t组输入,然后地图有n行m列,且n,m<=20.有一个最大跳跃距离d.后面输入一个n行的地图,每一个位置有一个值,代表这个位置的柱子可以经过多少个猴子.之后再输入一个地图'L'代表 ...
- POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流)
POJ 2711 Leapin' Lizards / HDU 2732 Leapin' Lizards / BZOJ 1066 [SCOI2007]蜥蜴(网络流,最大流) Description Yo ...
随机推荐
- OSS文件上传及OSS与ODPS之间数据连通
场景描述 有这样一种场景,用户在自建服务器上存有一定数量级的CSV格式业务数据,某一天用户了解到阿里云的OSS服务存储性价比高(嘿嘿,颜值高),于是想将CSV数据迁移到云上OSS中,并且 ...
- NMAP-端口扫描
1.时序选项 -T0 -> -T5 速度变快,但是准确性下降,nmap默认是T3 2.指定端口 3.扫描指定TCP和UDP端口 4.快速扫描常见100个端口 5.扫描常见的n的端口 6.TCP ...
- 3.azkaban3.0测试
测试目标 azkaban多executor下flow的分配方式 azkaban可以同时执行的flow\job个数 azkaban单个job最小使用的内存 相关配置 executor最大线程数: exe ...
- Thunder团队第五周 - Scrum会议1
Scrum会议1 小组名称:Thunder 项目名称:i阅app Scrum Master:杨梓瑞 工作照片: 邹双黛在照相,所以图片中没有该同学. 参会成员: 王航:http://www.cnblo ...
- Java数组课程作业
设计思路:生成随机数,赋值给数组.再将其求和输出 程序流程图: 源程序代码: import javax.swing.JOptionPane; public class Test { public st ...
- DAY3敏捷冲刺
站立式会议 工作安排 (1)服务器配置 (2)数据库配置 燃尽图 燃尽图有误,已重新修改,先贴卡片的界面,后面补修改后燃尽图 代码提交记录
- iOS- 给App添加内购& 验证购买iOS7新特性
1.内购——应用内购买 我所说的内购——也可以说是应用内购买 大家都知道通过苹果应用程序商店有三种主要赚钱的方式: 1.直接收费(与国内大部分用户的消费习惯相悖,如果要收费,直接收高的,别收6块钱) ...
- node中的__dirname
先说结论:__dirname指的是当前文件所在文件夹的绝对路径. 测试路径如下: 即 根目录/dir0.js 根目录/path1/dir1.js 根目录/paht1/path2/dir2.js 每个d ...
- [剑指Offer] 55.链表中环的入口结点
题目描述 一个链表中包含环,请找出该链表的环的入口结点. [思路]根据set集合的不重复,遍历链表时遇到的第一个重复结点就是环的入口结点. /* struct ListNode { int val; ...
- 一致性Hash算法(Consistent Hash)
分布式算法 在做服务器负载均衡时候可供选择的负载均衡的算法有很多,包括: 轮循算法(Round Robin).哈希算法(HASH).最少连接算法(Least Connection).响应速度算法(Re ...