Kundrapu N.
asked 07/21/17Island thunder strikes
There is an island in the Pacific Ocean and it receives heavy rainfall every year. It is also highly prone to thunder strikes during the monsoon.
The houses in the island are in connected blocks. The connected patterns in the houses are indicated as in the picture below. Here, 1 denotes a house and 0 denotes empty space.
Two houses are said to be connected if they are neighbors to each other. By neighbor we mean that they are adjacent to each other in one of the directions Up, Down, Left, Right.
As it is highly prone to thunder strikes, if a thunder strikes one region then all the houses in that region gets destroyed. The whole island is mapped by a M by N matrix of 0, 1s.
For example,
You are given a fixed number of thunder strikes, say n. Write a program to find the maximum number of houses that would be destroyed by the strikes.
Input
A line containing comma separated integers N, M indicating the size of the island
A line containing L, the number of thunder strikes on the island
N lines each containing M integers each of which s 0 or 1
The houses in the island are in connected blocks. The connected patterns in the houses are indicated as in the picture below. Here, 1 denotes a house and 0 denotes empty space.
Two houses are said to be connected if they are neighbors to each other. By neighbor we mean that they are adjacent to each other in one of the directions Up, Down, Left, Right.
As it is highly prone to thunder strikes, if a thunder strikes one region then all the houses in that region gets destroyed. The whole island is mapped by a M by N matrix of 0, 1s.
For example,
You are given a fixed number of thunder strikes, say n. Write a program to find the maximum number of houses that would be destroyed by the strikes.
Input
A line containing comma separated integers N, M indicating the size of the island
A line containing L, the number of thunder strikes on the island
N lines each containing M integers each of which s 0 or 1
More
1 Expert Answer
Andy C. answered 07/22/17
Tutor
4.9
(27)
Math/Physics Tutor
First, I apologize for the semantics, but thunder does not really strike and rarely destroys anything.
Lightening however does. The term "lightening" shall be used henceforth.
Also, the variable L is used in the input requirement to represent the number of lightening strikes,
which further supports the semantics.
Most importantly however there is a missing requirement.
Of the L lightening strikes, how do you know which location
does the lightening strike? Is the requirement to generate
a RANDOM location in the 2-D array, and then determine
which cluster of houses are destroyed from that location?
If not, then the location of each lightening strike must
be given in the input file, which you did not mention.
Following the integer L, you will have to read from
the file an array of (X,Y) coordinates representing
the array indices of where each of the L lightening bolts
will strike.
By lack of this input data, it APPEARS as though the
location of each lightening strike is to be RANDOMLY
generated.
Intuition and "gut instinct" tells me
recursion will then be needed to determine
which bits in the array need to flip from 1 to 0.
Clarification of this requirement is equally if not
more important than a picture. But sample I/O
will help.
Finally, which programming language are you
required to use? My preference is Java or Visual Basic.
I also have a Pascal compiler.
Third, is it a text or binary file?
Follow up with me on here with the answer
to those three questions and we can then begin
designing, implementing, and coding your solution.
Andy C.
Yes, I have a working recursive java routine which counts the number of houses destroyed
and updates the 2D array accordingly.
The input data is hard-coded for now. File Input and random number
generation is the next step.
Report
07/22/17
Still looking for help? Get the right answer, fast.
Ask a question for free
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Find an Online Tutor Now
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Mark M.
07/21/17