constructing a square matrix of edge N, and its element should not be same across same row and column

江枫思渺然 提交于 2020-01-14 07:07:44

问题


So, I was constructing a matrix (square) of length N, its element i should between 1 <= i < 2 * N

  • Each element should be between 1 to 2 * N - 1
  • for each i and j (1 <= i <= N and 1 <= j < 2 * N) the j element should appear in ith row / i column

for any N
if the desired matrix is not possible we have print -1;

Which means for N = 2

We could get matrix as -

1 2
3 1

As we can see for 1st row and column we can get 1 , 2 , 3. and for 2nd row and column we get 1, 2, 3

Another example : for N = 4

1 2 4 6
3 1 6 5
5 7 1 3
7 4 2 1

please help.

来源:https://stackoverflow.com/questions/59630967/constructing-a-square-matrix-of-edge-n-and-its-element-should-not-be-same-acros

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