Flood fill算法是从一个区域中提取若干个连通的点与其他相邻区域区分开的经典算法。因为其思路类似洪水从一个区域扩散到所有能到达的区域而得名。在GNU Go和扫雷中,Flood Fill算法被用来计算需要被清除的区域。
https://www.educative.io/edpresso/what-is-the-flood-fill-algorithm
The flood fill algorithm is used to determine the properties of the area around a particular cell in a block. The algorithm is implemented in the bucket fill tool of the Microsoft Paint program(桶填充), which colors the similarly colored pixels, or cells, with another color.


//Flood fill algorithm implemented in Java
class Example {
public static int M=8;
public static int N=8;
static void floodFill(int [][] myScreen, int x, int y, int currColor, int newColor)
{
// Base cases
if (x < 0 || x >= Example.M || y < 0 || y >= Example.N)
return;
if (myScreen[x][y] != currColor)
return;
if (myScreen[x][y] == currColor)
return;
// Replace the color at cell (x, y)
myScreen

Flood Fill算法是一种用于区分相连区域的经典算法,常见于GNU Go和扫雷游戏。该算法通过类似洪水扩散的方式填充区域,如在Microsoft Paint的桶填充工具中,用于将相似颜色的像素替换为新颜色。了解此算法的实现及其在像素着色中的应用。
最低0.47元/天 解锁文章
396

被折叠的 条评论
为什么被折叠?



