|
||||||||||
GameTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 995 Accepted Submission(s): 250 Problem Description Sea5 and wzh are playing games. There are some guards on an n ¡Á m chessboard. Every guard can attack eight cells around him and release shockwave to attack the whole row and column where he stand. Sea5 and wzh are at the beginning stage of the game, they have already put some guards on the chess cells. No guards can be attacked by another guard right now. So they all fell asleep. An innocent passer-by is on the chessboard. He can move to up, down, left or right from where he stands. The guards won¡¯t attack him unless the passer-by move to where they stand. The innocent man may appear at any point on the chessboard and move to any point. The innocent passer-by wants to know the average shortest distance of all the ways he can move without attacked by guards. Input Multiple test cases. The first line is an integer $T (T \leq 50)$, the number of cases. For each case, first line is two integers $n$ and $m (2 \leq n, m, \leq 1000)$. The next $n$ lines contain $m$ symbols indicate the cells of chessboard. ¡®G¡¯ indicates a guard and ¡®#¡¯ indicates an empty cell. Output One line per case, shortest distance of all the ways the passer-by can move without attacked by guards. Round the answer to four decimals. Sample Input
Sample Output
Hint Ways of distance 0: 3 Ways of distance 1: 4 Ways of distance 2: 2 The answer is (3 * 0 + 1 * 4 + 2 * 2) / (3 + 4 + 2) Author HIT Source | ||||||||||
|