2757. Maze Stretching

单点时限: 5.0 sec

内存限制: 256 MB

Usually the path in a maze is calculated as the sum of steps taken from the starting point until the ending point, assuming that the distance of one step is exactly 1. Lets assume that we could “stretch” (shorten or extend) the maze in vertical dimension (north-south). By stretching, we are just changing the passed distance between two cells. (it becomes X instead of one). We have a two dimensional maze which has ‘#’ for walls, ‘S’ in the starting cell and ‘E’ at the ending cell.

Due to outside conditions, we need to make the shortest path to be exactly L in size.

We are not allowed to change the maze configuration, nor to make any changes in the horizontal dimension. We are only allowed to stretch the vertical dimension, and that can be done by any percentage.

Find the percentage of the stretch P, for which the shortest path of the maze will be exactly L.

输入格式

First line of the input contains the number of test cases. For each test case, firstly two numbers L and N are given, where L is the required length of the shortest path and N is the number of lines that are given describing the maze. The following N lines describes the maze such as that each line describes a row of the maze. (Each row length is the horizontal dimension of the maze).

输出格式

For each test case output the percentage of the stretch in the following format:

Case #K: P%

P should have leading zero if the number is between 0 and 1.

P should be rounded up on 3 decimals, and always formatted on 3 decimals (with trailing zeros if needed).

Constraints

The height and width of the maze are maximum 100 cells.

All the lines describing one maze are the same size.

There will always be a solution.

The result will be between 0.000 and 1000.000 inclusive

There will be no direct horizontal only path connecting ‘S’ and ‘E’. (the result is always unique).

样例

Input
2
2.5 4
#####
#S..#
#..E#
#####
21 13
############
#S##.....#E#
#.##..#..#.#
#...#.#..#.#
###.#.#..#.#
#...#.#..#.#
#..##.#..#.#
##..#.#..#.#
###.#.#..#.#
##..#.#..#.#
#..##.#....#
#.....#....#
############
Due to some reason of our OJ , the dot just stand for space, and there is no dot in the testdata
Output
Case #1: 50.000%
Case #2: 21.053%
Explanation of the first test case in the example: On the original maze, the length of the shortest path is 3 because there are two horizontal steps and a vertical one. Our goal is to make the length of the shortest path to be 2.5. That’s why we have to “stretch” the vertical dimension of the maze by a percentage value less than 100. In this case it is 50% which actually changes the vertical distance between two cells to 0.5.

5 人解决,10 人已尝试。

6 份提交通过,共有 38 份提交。

8.0 EMB 奖励。

创建: 15 年前.

修改: 7 年,2 月前.

最后提交: 6 年,7 月前.

来源: Southeastern European Regional Programming Contest 2009

题目标签