解题报告 之 SOJ2414 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。问你最终有几只蜥蜴被落下(没有跳到安全区域)。

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

POJ 3498 March of the Penguins
http://blog.csdn.net/maxichu/article/details/45103603

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

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

解题报告 之 SOJ2414 Leapin' Lizards

时间: 2024-10-13 18:45:04

解题报告 之 SOJ2414 Leapin' Lizards的相关文章

HDU - 2732 Leapin&#39; Lizards(ISAP Dinic EK)

题目大意:给出两张地图,第一章地图代表的是每根柱子的高度,第二张地图代表的是每只蜥蜴所在的位置 每根柱子只能站一只蜥蜴,蜥蜴离开该柱子时,柱子的高度会下降一个单元,当柱子的高度为0时,该柱子将不可用 现在给出每只蜥蜴能跳跃的距离,问最少有多少只蜥蜴逃不出来 解题思路:将柱子拆成2个点,权值为柱子的高度 将每只蜥蜴所在的位置和超级源点连接,权值为1 将能通到外界的柱子连接到超级汇点,权值为INF 如果柱子间的距离满足蜥蜴跳跃的距离,连接起来,权值为INF 这样图就完成了 ISAP: #includ

解题报告 之 POJ3057 Evacuation

解题报告 之 POJ3057 Evacuation Description Fires can be disastrous, especially when a fire breaks out in a room that is completely filled with people. Rooms usually have a couple of exits and emergency exits, but with everyone rushing out at the same time

hdu 1541 Stars 解题报告

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1541 题目意思:有 N 颗星星,每颗星星都有各自的等级.给出每颗星星的坐标(x, y),它的等级由所有比它低层(或者同层)的或者在它左手边的星星数决定.计算出每个等级(0 ~ n-1)的星星各有多少颗. 我只能说,题目换了一下就不会变通了,泪~~~~ 星星的分布是不是很像树状数组呢~~~没错,就是树状数组题来滴! 按照题目输入,当前星星与后面的星星没有关系.所以只要把 x 之前的横坐标加起来就可以了

【百度之星2014~初赛(第二轮)解题报告】Chess

声明 笔者最近意外的发现 笔者的个人网站http://tiankonguse.com/ 的很多文章被其它网站转载,但是转载时未声明文章来源或参考自 http://tiankonguse.com/ 网站,因此,笔者添加此条声明. 郑重声明:这篇记录<[百度之星2014~初赛(第二轮)解题报告]Chess>转载自 http://tiankonguse.com/ 的这条记录:http://tiankonguse.com/record/record.php?id=667 前言 最近要毕业了,有半年没做

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告

2016 第七届蓝桥杯 c/c++ B组省赛真题及解题报告 勘误1:第6题第4个 if最后一个条件粗心写错了,答案应为1580. 条件应为abs(a[3]-a[7])!=1,宝宝心理苦啊.!感谢zzh童鞋的提醒. 勘误2:第7题在推断连通的时候条件写错了,后两个if条件中是应该是<=12 落了一个等于号.正确答案应为116. 1.煤球数目 有一堆煤球.堆成三角棱锥形.详细: 第一层放1个, 第二层3个(排列成三角形), 第三层6个(排列成三角形), 第四层10个(排列成三角形). -. 假设一共

[noip2011]铺地毯(carpet)解题报告

最近在写noip2011的题,备战noip,先给自己加个油! 下面是noip2011的试题和自己的解题报告,希望对大家有帮助,题目1如下 1.铺地毯(carpet.cpp/c/pas) [问题描述]为了准备一个独特的颁奖典礼,组织者在会场的一片矩形区域(可看做是平面直角坐标系的第一象限)铺上一些矩形地毯.一共有n 张地毯,编号从1 到n.现在将这些地毯按照编号从小到大的顺序平行于坐标轴先后铺设,后铺的地毯覆盖在前面已经铺好的地毯之上.地毯铺设完成后,组织者想知道覆盖地面某个点的最上面的那张地毯的

ACdream 1203 - KIDx&#39;s Triangle(解题报告)

KIDx's Triangle Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description One day, KIDx solved a math problem for middle students in seconds! And than he created this problem. N

解题报告 之 CodeForces 91B Queue

解题报告 之 CodeForces 91B Queue Description There are n walruses standing in a queue in an airport. They are numbered starting from the queue's tail: the 1-st walrus stands at the end of the queue and the n-th walrus stands at the beginning of the queue.

解题报告 之 POJ1226 Substrings

解题报告 之 POJ1226 Substrings Description You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be found as a substring of any of the given strings. Input The first li