码迷,mamicode.com
首页 > Windows程序 > 详细

解题报告 之 SOJ2414 Leapin' Lizards

时间:2015-04-26 10:54:58      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:解题报告   soj   2414   leapin lizards   最大流   

解题报告 之 SOJ2414 Leapin‘ Lizards


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.

Warning: Brute force methods examining every path will likely exceed the allotted time limit.

Example input: Example output:
4
3 1
1111
1111
1111
LLLL
LLLL
LLLL
3 2
00000
01110
00000
.....
.LLL.
.....
3 1
00000
01110
00000
.....
.LLL.
.....
5 2
00000000
02000000
00321100
02000000
00000000
........
........
..LLLL..
........
........
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.

Last modified on October 30, 2005 at 1:15 PM.


题目大意:首先膜拜一下SOJ高超的英语水平。题目清晰易懂,没有歧义且输出时的小陷阱展示了完美的语法。(当然其他OJ的还是题目也是很好懂的比如ZOJ的)。。。然后开始说说题目大意:一个房间有一个网格,每个交叉点都是一根柱子,网格的边界是安全区域。一些柱子上有一只蜥蜴,现在他们要跳到边界的安全区域。但是不同的柱子有不同的承受力,分别可以承受[0,3]次跳跃。所有蜥蜴跳跃的最大半径为d。问你最终有几只蜥蜴被落下(没有跳到安全区域)。

分析:是经典的最大流模型,有一道同样模型的题请戳链接:

技术分享

那么是怎么解决的呢?首先每根柱子都是一个节点,然后这些柱子需要拆点,负载为最大承受力,如果不拆点可能由于多次流量转移而导致实际流量可能大于可行流量。同时,每根柱子的入点连接所有与它距离<=d的柱子的拆点出点,表示可以跳过去,负载为INF(这里我是四重循环枚举两辆根柱子),因为承受力是在拆点处限制的。然后如果如果柱子上有蜥蜴,则超级源点连一条边到该柱子的出点,负载为1;如果某柱子到任一边界的距离<=d,则连一条边到超级汇点,负载为INF。再跑最大流看看被留下了几只,然后用蜥蜴数量减即可。

最后注意输出的 单复数+s和be动词的统一即可!不然就WA死啦!

解题报告 之 SOJ2414 Leapin' Lizards

标签:解题报告   soj   2414   leapin lizards   最大流   

原文地址:http://blog.csdn.net/maxichu/article/details/45286085

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!