Problem Solving report SOJ2414 Leapin ' lizards
Description
Your platoon of wandering Lizards has entered a strange the The Labyrinth is exploring. As you is looking around for hidden treasures, one of the rookies steps in an innocent-looking stone and the the "s floor Suddenly disappears! Each lizard in your platoon are 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 the-the-same, and report the number of casualties.
The pillars in the class is aligned as a grid, with each pillar one unit away from the pillars to it east, west, north an D South. Pillars at the edge of the grid is one unit away from the edge of the The (safety). Not all pillars necessarily has a lizard. A Lizard is able to leap onto any unoccupied pillar the is within D units of he current one. A lizard standing on a pillar within leaping distance of the edge of the the-the-the-all leap to safety ... but there ' s a C Atch:each pillar becomes weakened after each jump, and would 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-pillar at any given time.
Input: the input file would begin with a line containing a single integer representing the number of test cases, which is at the most 25. Each test case would 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. Both maps would follow, each as a map of characters with one row per line. The first map would contain a digit (0-3) in each position representing the number of jumps the pillar in that position wil L Sustain before collapsing (0 means there is no pillar there). The second map would follow, with an ' L ' for every position where a lizard are on the pillar and a < tt> '. ' for every empty pillar. There'll never be a lizard to a position where there is no pillar.
Each input map was 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 this could not escape. The format should follow the samples provided below.
Warning: Brute force methods examining every path would 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 is left behind. Case #3:3 lizards were left behind. Case #4:1 lizard is left behind. |
Last modified in October, 2005 at 1:15 PM.
The main topic: first worship SOJ superb English proficiency. The problem is clear and easy to understand, without ambiguity and the output of the small trap shows the perfect grammar. (Of course, other OJ or the topic is very understood, such as Zoj) ... Then start talking about the main idea: a room has a grid, each intersection is a pillar, the grid boundary is a safe area. There is a lizard on some pillars, and now they are jumping to the safe zone of the border. But different pillars have different endurance, can withstand [0,3] times jump. The maximum radius for all lizard jumps is d. Ask you how many lizards were eventually dropped (not jumping to the safe zone).
Analysis: Is the classic maximum flow model, there is a same model of the problem poke link: POJ 3498 March of the Penguinshttp://blog.csdn.net/maxichu/article/details/45103603
So what's the solution? First, each pillar is a node, and then these pillars need to be split, the load is the maximum endurance, if not split may be due to multiple traffic transfer and the actual traffic may be greater than the feasible traffic. At the same time, the entry point of each pillar is connected to the point at which it is removed from the pillar of the <=d, indicating that it can jump over, the payload is INF (here I am the four-cycle enumeration of two root pillars), because the endurance is limited at the point of separation. Then if there is a lizard on the post, the super source point is connected to the point of the pillar, with a load of 1, and if the distance of a pillar to any one boundary <=d, then one edge to the Super meeting point, the payload is INF. Run the maximum flow to see how many have been left, and then use the number of lizards to reduce.
Finally, note the unity of the single and complex +s of the output and the BE verb! Or WA's dead!
Problem Solving report SOJ2414 Leapin ' lizards