F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Game

Time 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
1 2 2 ## G#
 

Sample Output
0.8889
 

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
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 18:03:46, Gzip enabled