# 加快充水

``````def floodfill(planet, x1, y1):

width = len(planet[0])
height = len(planet)
list = [(y1, x1)]
if planet[y1][x1] == " ":
for y, x in list:
planet[y][x] = "0"
list.pop()
for x2 in range(min(max(x - 1, 0), width), min(max(x + 2, 0), width)):
for y2 in range(min(max(y - 1, 0), height), min(max(y + 2, 0), heigth)):
if planet[y2][x2] == " ":
list.append((y2, x2))
``````

``````planet = [
[" ", " ", " ", "x", " ", " ", " ", " ", " ", " ", " ", "x", " "],
[" ", " ", "x", "x", " ", " ", " ", "x", " ", " ", " ", "x", " "],
[" ", "x", "x", " ", " ", " ", " ", "x", " ", " ", "x", "x", " "],
["x", "x", "x", "x", "x", " ", " ", "x", " ", "x", " ", " ", " "],
["x", "x", "x", "x", " ", " ", " ", " ", "x", " ", "x", " ", " "],
[" ", " ", "x", " ", " ", " ", " ", " ", " ", "x", " ", " ", " "]
]
``````

``````   0 1 2 3 4
0   x   x x
1     x x
2 x
3 x x   x
4 x x x
5   x x x x
``````

``````0 x 0 x x
0 0 x x 0
x 0 0 0 0
x x 0 x 0
x x x 0 0
x x x x
``````

``````0 x 0 x x
0 0 x x
x 0     0
x x 0 x 0
x x x 0
x x x x
``````