算法找到一个随机矩阵从一个点相同的元素 [英] Algorithm to find same element from a point in a random matrix

查看:140
本文介绍了算法找到一个随机矩阵从一个点相同的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道关于我该怎么做才能找到,在一个随机矩阵,从一个特定的点,并围绕这个点的每个相同的元素。

它更容易在一个例子来说明:

所以,在绿色的是玩家选择的一点。我怎样才能得到所有这些X(仅行和列,而不是对角线)的位置?我想过像Dijkstra算法或算法贝尔曼福特?

我希望你明白,对不起我的英文不好。

感谢

解决方案

喜欢的东西深度优先搜索(DFS)广度优先搜索(BFS)可能是你要找的。

DFS:

  • 开始在选定的单元格。

  • 递归探讨在各个方向,但不探索已经访问过的细胞。

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

解决方案

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.

这篇关于算法找到一个随机矩阵从一个点相同的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆