Algorithm to find same element from a point in a random matrix

倖福魔咒の 提交于 2019-12-25 17:00:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!