Question: N JAVA WITH FLOODFILL ALOGRITHM The tasks is to write a recursive program to count the number of muck-free regions. The IRL is represented by

N JAVA

WITH FLOODFILL ALOGRITHM

N JAVA WITH FLOODFILL ALOGRITHM The tasks is to write a recursive

The tasks is to write a recursive program to count the number of muck-free regions. The IRL is represented by a two-dimensional rectangle squares. Each square contains either muck ('M') or sand ('.'). A region is defined as a connected set of one of more squares with sand in it, where a square is considered to connect to all eight of its adjacent squares. Floodfill algorithm The task can be accomplished quite easily with a well-know, recursive algorithm called floodfill. This algorithm is used in the "bucket" fill tool of paint programs to fill connected, similarly-colored areas with a different color, and in games such as Go and Minesweeper for determining which pieces are cleared. It is a particularly easy algorithm to implement recursively on a two dimensional grid. The algorithm works by "painting" or "flooding" the current cell and then recursing on all the neightboring cells. It is necessary to avoid going into regions that are already flooded or inaccessible. Input Format All the input comes from the standard input stream. The first line of the input consists of two space-separated integers: N and M(1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!