博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU2732 最大流
阅读量:4966 次
发布时间:2019-06-12

本文共 4654 字,大约阅读时间需要 15 分钟。

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
43 1111111111111LLLLLLLLLLLL3 2000000111000000......LLL......3 1000000111000000......LLL......5 20000000002000000003211000200000000000000..................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.
 
 
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
#include
#include
#include
#include
using namespace std;const int INF=0x7fffffff;const int MAXN=1000;const int MAXM=10000;int S,T,tot,head[MAXN+9],h[MAXN+9];char mp[30][30];int Abs(int x) { return x>=0?x:-x; }struct Edge{ int to,next,w;}edge[MAXM+9];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=0; edge[tot].next=head[y]; head[y]=tot++;}void init(int x){ S=0;T=x; tot=0; memset(head,-1,sizeof(head));}bool bfs(){ queue
q; memset(h,-1,sizeof(h)); q.push(S); h[S]=0; while(!q.empty()){ int u=q.front();q.pop(); for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].to; if(edge[i].w&&h[v]<0){ q.push(v); h[v]=h[u]+1; } } } if(h[T]==-1) return 0; return 1;}int dfs(int u,int f){ if(u==T) return f; int x,used=0; for(int i=head[u];i!=-1;i=edge[i].next){ int v=edge[i].to; if(edge[i].w&&h[v]==h[u]+1){ x=f-used; x=dfs(v,min(x,edge[i].w)); edge[i].w-=x; edge[i^1].w+=x; used+=x; if(used==f) return f; } } if(!used) h[u]=-1; return used;}int dinic(){ int ans=0; while(bfs()) ans+=dfs(S,INF); return ans;}int main(){ int n,m,d; scanf("%d%d%d",&n,&m,&d); init(n*m*2+1); for(int i=0;i

 

转载于:https://www.cnblogs.com/--ZHIYUAN/p/6374497.html

你可能感兴趣的文章
Android中全屏或者取消标题栏
查看>>
处理器管理与进程调度
查看>>
页面懒加载
查看>>
向量非零元素个数_向量范数详解+代码实现
查看>>
java zip 中文文件名乱码_java使用zip压缩中文文件名乱码的解决办法
查看>>
java if 用法详解_Java编程中的条件判断之if语句的用法详解
查看>>
kafka的java客户端_KAFKA Producer java客户端示例
查看>>
java -f_java学习笔记(一)
查看>>
java 什么题目好做_用java做这些题目
查看>>
java中的合同打印_比较方法违反了Java 7中的一般合同
查看>>
php 位运算与权限,怎么在PHP中使用位运算对网站的权限进行管理
查看>>
php include效率,php include类文件超时
查看>>
matlab sin函数 fft,matlab的fft函数的使用教程
查看>>
wcdma下行如何解扩解扰 matlab,WCDMA技术基础.ppt
查看>>
MySQL date_format() 函数
查看>>
mysql 时间处理
查看>>
mysql adddate()函数
查看>>
mysql addtime() 函数
查看>>
mysql 根据日期时间查询数据
查看>>
mysql sin() 函数
查看>>