我想设计一种算法来显示以下模式:
1
9 2
10 8 3
14 11 7 4
15 13 12 6 5 是否有方法将其转换为以下数组并使用上述矩阵的索引,并找出数字在数组中的位置:1 9 2 10 8 3…
我找不到用矩阵协调来计算元素的模式,这就是为什么我试图用上面的方法来确定数组中下一个数字的位置。
发布于 2017-09-22 04:26:19
只是线索:
您需要知道算术级数和的公式(这里是自然数之和1 + 2 + 3 +.. N)。
1st step: determine number of diagonal where k-th item of array stands.
2nd step: get direction of this diagonal filling
3rd step: get number of place at this diagonal
4th step: find what number stands herehttps://stackoverflow.com/questions/46356130
复制相似问题