Coloring Pixels
Swipe to start coding
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
Tack för dina kommentarer!
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Sammanfatta detta kapitel
Explain code
Explain why doesn't solve task
Awesome!
Completion rate improved to 7.69
Coloring Pixels
Svep för att visa menyn
Swipe to start coding
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
Tack för dina kommentarer!
Awesome!
Completion rate improved to 7.69single