DFS những ô cùng màu thôi:
def dfs(x,y):
st = [(x,y)]
ans = 0
while len(st):
_x,_y = st.pop()
if not visited[_y][_x]:
ans+=1
visited[_y][_x] = True
for dy in range(-1,2):
for dx in range(-1,2):
xx = _x+dx
yy = _y+ dy
if xx<0 or xx>=width or yy<0 or yy>=height or visited[yy][xx] or not same(color[yy][xx],color[y][x]):
continue
st.append((xx,yy))
return ans
for i in range(height):
for j in range(width):
if not visited[i][j] :
#print(i,j)
ans = dfs(j,i)
if ans>10**4:
print(ans,color[i][j])
##update
Sau khi download lại ảnh (đúng size) thì kết quả:
###Có màu
214047 (255, 255, 255)
52080 (237, 28, 36)
44999 (255, 242, 0)
47252 (163, 73, 164)
53228 (0, 162, 232)
33378 (34, 177, 76)
35016 (255, 174, 201)
###Màu đỏ
214047 (255, 255, 255)
52080 (237, 28, 36)
44999 (237, 28, 36)
47252 (237, 28, 36)
53228 (237, 28, 36)
33378 (237, 28, 36)
35016 (237, 28, 36)