Hotel+Floors

We are given a top view of a hotel floor, which is represented by an MxN matrix of characters, composed of (only) the following: '#' is a Wall

'-' is Free Space

'*' is an occupied space (by a single person). We are required to evaluate the average number of people living in a room.
 * Constraints:**

M, N <= 100

Number of test-cases<= 10

All border edges of the map will be walls.

There will be at least one room.

Input
The 1st line contains the number of test inputs, with each test case consisting of:

M N

MxN matrix of characters

Output
For each test case output a line with the average number of people living per room, rounded to //exactly// two decimal places.

**Input**
2

5 5











6 10













**Output**
1.67

4.00

Reference
[]

Source Code code format="java" public class HotelFloors { public static void main(String[] args) { char[][] map = { {'#', '#', '#', '#', '#'},               {'#', '*', '*', '#', '#'},                {'#', '#', '#', '*', '#'},                {'#', '*', '*', '#', '#'},                {'#', '#', '#', '#', '#'}        };

begin(map); }

public static void begin(char[][] map) { int c = 0; int sum = 0;

for(int i = 0; i < map.length; i++) { for(int j = 0; j < map[0].length; j++) { if(map[i][j] != '#') { c++;

sum += eval(map, i, j); }           }        }

System.out.println((double)sum / c); }

public static int eval(char[][] map, int r, int c) { if(map[r][c] == '#') { return 0; }

int t = 0;

if(map[r][c] == '*') { t = 1; }

map[r][c] = '#';

return t + eval(map, r-1, c-1) + eval(map, r-1, c+1) + eval(map, r+1, c-1) + eval(map, r+1, c+1); } } code

Comment