Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Coloring Pixels | Solving the Problems using BFS
Breadth First Search
course content

Contenido del Curso

Breadth First Search

Breadth First Search

1. What is BFS
2. Practice
3. Improve Your Code
4. Solving the Problems using BFS

Coloring Pixels

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Example 1

Input: m=4, n=6, x=1, y=2

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

2 2 2 0 0 0

0 2 2 0 0 0

2 2 0 0 1 1

0 0 1 1 0 0

Example 2

Input: m=4, n=6, x=2, y=5

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 2 2

0 0 1 1 0 0

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 4. Capítulo 1
toggle bottom row

Coloring Pixels

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Example 1

Input: m=4, n=6, x=1, y=2

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

2 2 2 0 0 0

0 2 2 0 0 0

2 2 0 0 1 1

0 0 1 1 0 0

Example 2

Input: m=4, n=6, x=2, y=5

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 2 2

0 0 1 1 0 0

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 4. Capítulo 1
toggle bottom row

Coloring Pixels

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Example 1

Input: m=4, n=6, x=1, y=2

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

2 2 2 0 0 0

0 2 2 0 0 0

2 2 0 0 1 1

0 0 1 1 0 0

Example 2

Input: m=4, n=6, x=2, y=5

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 2 2

0 0 1 1 0 0

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Tarea

Imagine you have an image a of size m*n, and there are some areas painted black or white (marked 1 or 0 in array). When you touch the pixel a[i][j], you color it with number 2, and if you colored some pixel, you’ll also color all 4-directionally connected pixels of the same color.

Example 1

Input: m=4, n=6, x=1, y=2

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

2 2 2 0 0 0

0 2 2 0 0 0

2 2 0 0 1 1

0 0 1 1 0 0

Example 2

Input: m=4, n=6, x=2, y=5

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 1 1

0 0 1 1 0 0

Output:

1 1 1 0 0 0

0 1 1 0 0 0

1 1 0 0 2 2

0 0 1 1 0 0

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 4. Capítulo 1
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt