You managed to beat your friend in Battleships and take his points! Perfectly legitimately, of course. However, for some strange reason he's upset, and now challenges you to a rematch - this time at the game of Advanced Battleships, and with even higher stakes!
You each have a grid of
You know for a fact that you can distract your friend for a brief
moment, this time by telling him that someone solved
Good Hunting Will, but this trick will again only
work exactly once. While he isn't looking, you'll have time to snatch up
some of his ships with one hand. Your hand can cover a square of exactly
Of course, your friend is no fool, so he's got his grid well concealed.
As such, you don't know anything about it except its size, so when the
time comes, you'll just choose a random square of size
As usual, these bets attract large crowds. One of the bystanders who can see your opponent's grid knows your plan, and is curious as to the expected number of ships that you will grab (in other words, the average number of ships out of all the possible snatches you could make). Nerdy though he is, he can't calculate it in his head, so he runs over to a computer and codes up a program…
Input Specification
The first line of input will contain 3 integers —
The next X
represents a ship, while a .
represents an empty cell.
Output Specification
A single number - the expected number of ships that you'll grab. It must
be within
Sample Input
5 5 2
XXXX.
X..X.
X..X.
X....
.XX..
Sample Output
0.875
Explanation
There are
1 1 1 1
1 0 1 1
1 0 1 1
2 1 1 0
This is a total of
Comments
th is this memory limit >:(