问题
I'm wondering on how can I do to find, in a random matrix, each same elements from a particular point, and around this point.
It's easier to explain in an example :
So, in green it is the point that the player chooses. How can I get the position of all these "X" (only lines and columns, not diagonal) ? I thought about an algorithm like Dijkstra or Bellman Ford ?
I hope you understand, and sorry for my bad english.
Thanks
回答1:
Something like depth-first search (DFS) or breadth-first search (BFS) is probably what you're looking for.
DFS:
Start at the chosen cell.
Recursively explore in all directions, but don't explore already visited cells.
来源:https://stackoverflow.com/questions/23222712/algorithm-to-find-same-element-from-a-point-in-a-random-matrix