| At the arcade, you can play a simple game where a ball is dropped into the top |
| of the game, from a position of your choosing. There are a number of pegs |
| that the ball will bounce off of as it drops through the game. Whenever the |
| ball hits a peg, it will bounce to the left with probability 0.5 and to the |
| right with probability 0.5. The one exception to this is when it hits a peg on |
| the far left or right side, in which case it always bounces towards the |
| middle.<br/><br/> |
| When the game was first made, the pegs where arranged in a regular grid. |
| However, it's an old game, and now some of the pegs are missing. Your goal in |
| the game is to get the ball to fall out of the bottom of the game in a |
| specific location. Your task is, given the arrangement of the game, to |
| determine the optimal place to drop the ball, such that the probability of |
| getting it to this specific location is maximized.<br/><br/> |
| The image below shows an example of a game with five rows of five columns. |
| Notice that the top row has five pegs, the next row has four pegs, the next |
| five, and so on. With five columns, there are four choices to drop the ball |
| into (indexed from 0). Note that in this example, there are three pegs |
| missing. The top row is row 0, and the leftmost peg is column 0, so the |
| coordinates of the missing pegs are (1,1), (2,1) and (3,2). In this example, |
| the best place to drop the ball is on the far left, in column 0, which gives a |
| 50% chance that it will end in the goal. |
|
|
| <pre> |
| x.x.x.x.x |
| x...x.x |
| x...x.x.x |
| x.x...x |
| x.x.x.x.x |
| G |
|
|
| 'x' indicates a peg, '.' indicates empty space. |
| </pre> |
| <h3> |
| Input |
| </h3> |
| You should first read an integer <b>N</b>, the number of test cases. Each of the |
| next <b>N</b> lines will then contain a single test case. Each test case will start |
| with integers <b>R</b> and <b>C</b>, the number of rows and columns (<b>R</b> |
| will be odd). Next, an integer <b>K</b> will specify the target column. |
| Finally, an integer <b>M</b> will be followed by <b>M</b> pairs of integer |
| <b>r<sub>i</sub></b> and <b>c<sub>i</sub></b>, giving the locations of the |
| missing pegs. |
| <h3>Constraints</h3> |
| <ul> |
| <li>1 ≤ <b>N</b> ≤ 100</li> |
| <li>3 ≤ <b>R</b>,<b>C</b> ≤ 100</li> |
| <li>The top and bottom rows will not have any missing pegs.</li> |
| <li>Other parameters will all be valid, given <b>R</b> and <b>C</b></li> |
| </ul> |
| <h3> |
| Output |
| </h3> |
| For each test case, you should output an integer, the location to drop the |
| ball into, followed by the probability that the ball will end in columns |
| <b>K</b>, formatted with exactly six digits after the decimal point (round the |
| last digit, don't truncate). |
| <h3> |
| Notes |
| </h3> |
| The input will be designed such that minor rounding errors will not impact the |
| output (i.e. there will be no ties or near -- up to 1E-9 -- ties, and the direction of rounding |
| for the output will not be impacted by small errors). |
|
|
|
|