(SPOJ) Colorindo - Solution
Link to the problem: http://br.spoj.com/problems/COLOR11/ This problem wants us to find the amount of squares that a child can paint using only a color. One way of solving this problem is using Flood Fill, an algorithm that finds all the squares of the matrix that are connected to the initial square. The solution below is using a non-recursive implementation (Breath-First Search) to find the answer. import java.io.*; import java.util.*; class Main { public int numRows; public int numCols; public int[][] matrix; public boolean[][] visited; public int count; public int[] vi = {-1,-1,-1,0,0,1,1,1}; public int[] vj = {-1,0,1,-1,1,-1,0,1}; public void bfs(int currI, int currJ) { Queue<Coord> queue = new ArrayDeque<Coord>(); ...