MLASERP - Laser Phones


The cows have a new laser-based system so they can have casual
conversations while out in the pasture which is modeled as a W x H
grid of points (1 <= W <= 100; 1 <= H <= 100).

The system requires a sort of line-of-sight connectivity in order
to sustain communication. The pasture, of course, has rocks and
trees that disrupt the communication but the cows have purchased
diagonal mirrors ('/' and '\' below) that deflect the laser beam
through a 90 degree turn. Below is a map that illustrates the
problem.

H is 8 and W is 7 for this map.  The two communicating cows are
notated as 'C's; rocks and other blocking elements are notated as
'*'s:

7 . . . . . . .         7 . . . . . . .
6 . . . . . . C         6 . . . . . /-C
5 . . . . . . *         5 . . . . . | *
4 * * * * * . *         4 * * * * * | *
3 . . . . * . .         3 . . . . * | .
2 . . . . * . .         2 . . . . * | .
1 . C . . * . .         1 . C . . * | .
0 . . . . . . .         0 . \-------/ .
  0 1 2 3 4 5 6           0 1 2 3 4 5 6

Determine the minimum number of mirrors M that must be installed
to maintain laser communication between the two cows, a feat which
is always possible in the given test data.

INPUT

* Line 1: Two space separated integers: W and H

* Lines 2..H+1: The entire pasture.

SAMPLE INPUT  

7 8
.......
......C
......*
*****.*
....*..
....*..
.C..*..
.......
OUTPUT
* Line 1: A single integer: M

SAMPLE OUTPUT 

3
Any suggestted testcase will be welcomed.

hide comments
minhthai: 2016-03-16 05:43:38

such a nice problem!
signal cannot go diagonally, don't worry.

kejriwal: 2015-12-21 21:15:22

awesome prob. !!

Ankur Singh: 2015-10-26 05:13:58

will there be always two cows in the map ??

Hussain: 2015-09-07 22:38:59

Nice problem, try to solve this after you're done http://www.spoj.com/problems/CERC07K

newbie: 2015-06-08 06:07:48

enjoyed solving this , nice problem !!!

(@#$*__): 2015-01-25 14:08:13

Really! nice one :-)

kelaseek: 2014-12-22 12:48:05

why wrong answer? pls check

Archit Jain: 2014-07-21 21:04:01

enjoyed solving it

Jignesh: 2013-04-01 17:31:23

@francky i just wanted to know what do they mean by "line of sight" , can Cows diagonally placed communicate directly..... I know the forum thing.
--ans(francky)--> No, I think light goes North-South or East-West, and you need one mirror for two cows in "diagonal" without trees.

Last edit: 2013-04-01 19:25:35
Jignesh: 2013-04-01 16:02:59

what should be the ans for <. snip .>
--edit(francky)--> Please, see the notes below, and use the forum.

Last edit: 2013-04-01 17:16:26

Added by:~!(*(@*!@^&
Date:2009-02-13
Time limit:0.227s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:JAN09 SILVER Division