Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Language: Maze Stretching
Description 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. Input 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). Output 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). Sample Input 2 2.5 4 ##### #S # # E# ##### 21 13 ############ #S## #E# # ## # # # # # # # # ### # # # # # # # # # # ## # # # ## # # # # ### # # # # ## # # # # # ## # # # # # ############ Sample Output Case #1: 50.000% Case #2: 21.053% Hint 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). 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. Source |
[Submit] [Go Back] [Status] [Discuss]
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator