Under construction

Still being built. Things may change

The Deer Hunter

Time limit3sMemory limit1024 MB

Summary
Find the shortest chase time for P-22 to catch a deer that flees straight away after he steps on a noisy cell, or -1 if he cannot.
Level

Medium6 of 10

Topics
BFS, Geometry, Graph
Solved
No attempts yet

Problem

P-22 eats deer, rabbits, and other animals in Griffith Park. He rarely attacks pets, though he is a prime suspect in the 2016 death of an elderly koala at the Los Angeles Zoo. Deer are very alert. You have to sneak up on them carefully, and if they hear or smell you before you pounce, you must run faster to catch them before they reach safety.

The hunting area is a rectangle. While sneaking, P-22 can move horizontally or vertically, but not diagonally. You are given the starting positions of P-22 and a grazing deer. Both start at the center of their squares. Each square is either silent or noisy. While P-22 stays on silent squares, the deer does not notice him. When he steps onto a noisy square, the deer starts running.

Precisely: while sneaking, each step starts and ends with P-22 at the center of a square. He makes noise when his center is at the center of a noisy square, not when he merely touches its edge.

When the deer starts running, it runs in a straight line directly away from P-22 at speed vDv_D. The line ignores the grid of the map. At that moment P-22 starts running at speed vPv_P and follows the deer in a straight line. If he catches the deer before it reaches the edge of the area, he has a meal. Otherwise he goes hungry. The deer reaches the edge when its center touches the outer boundary of the area.

Running is much harder work than sneaking, so P-22 wants to run as briefly as possible. Find the shortest running time that P-22 can guarantee while still catching the deer.

Input

The first line contains 1≤K≤1001 \le K \le 100, the number of data sets. Each data set starts with a line containing two integers 1≤X,Y≤10001 \le X, Y \le 1000 and two real numbers vP,vD>0v_P, v_D > 0. XX and YY are the width and height of the hunting area, and vPv_P and vDv_D are the running speeds of P-22 and the deer.

Then YY lines follow, each with XX characters. Character xx of line yy describes the square in column xx of row yy:

  • . is silent terrain.
  • # is noisy terrain.
  • P is P-22's starting square.
  • D is the deer's starting square.

Both starting squares are silent. Each data set contains exactly one P and exactly one D.

Output

For each data set, print Data Set x: on its own line, where xx is the data set number. On the next line, print the minimum running time of a successful hunt, rounded to two decimals. If P-22 cannot catch the deer, print -1 instead. Remember that P-22 and the deer are located at the centers of their squares, and the escape point is the outer edge of the area. Print a blank line after each data set.

Examples1

  1. Example 1

    Input
    2
    9 8 1.44 1.2
    .........
    .########
    ......#D#
    #####.###
    .........
    .########
    .........
    ########P
    7 6 3.9 1.4
    .......
    ....D..
    .......
    .......
    #######
    P......
    
    Expected output
    Data Set 1:
    4.17
    
    Data Set 2:
    -1