Asking for a programming problem? Print an n order Rubik s Cube, which is required to be written in

Updated on technology 2024-05-17
2 answers
  1. Anonymous users2024-02-10

    The odd Rubik's Cubes are arranged on a square matrix of nxn (n is an odd number), which requires the sum of each row, column and diagonal to be the same. As shown in the figure below, it is an odd Rubik's cube with n=5.

    The method of filling the Rubik's cube is the simplest with the odd number of Rubik's cubes, the first number is placed in the first line of the positive ** (filled in 1), and then filled in to the right (left), if there are numbers on the right (left), then fill in down, as shown in the following figure:

    In order to facilitate the calculation, we use the part of the index 1 to n, and when the calculation is to the right (left) up or down, we can divide the index value by the n value, if the remainder is 1, it will go down, otherwise it will go up to the right (left).

    4n Rubik's Cube.

    It is the same as the odd magic square, in that the sum of the rows, columns and diagonals is equal, but the difference is that the dimension of the square matrix is a multiple of 4.

    Let's take a look at the solution of the 4x4 square matrix first

    To put it simply, one is to fill in from the top left from 1 in order, but do not fill in the diagonal, and the other from the top left from 16, but only fill in the diagonal, and then put the two together to solve the problem. If n is greater than or equal to 2, then draw a diagonal line in 4x4 as shown below:

    As for how to judge the position of the diagonal, there are two formulas, and those who are interested can draw a picture to confirm it, as follows:

    Top left to bottom right: j % 4 == i % 4

    Top Right to Bottom Left: (j % 4 + i % 4) == 1

    The results of the 8th-order Rubik's Cubes (n=2) are as follows:

  2. Anonymous users2024-02-09

    .Initialize Create an n*n square matrix (n is an odd number), and fill it with 0 to represent the square array with the integer h, and v to represent the square array rows.

    h = n-1

    v = n/2

    Initialization completed.

    Start 1Judgment: Whether the number is filled in or not.

    Yes: End.

    No: Current: Fill in.

    Yes: Next: Out-of-bounds coordinates set to 0

    No: Continue.

    No: Current: h minus 1, v unchanged, turn 1

    End include

    #include

    struct stpos

    cur, next;

    - Define the representation of the columns and columns of the square: h for columns, v for rows --*int main().

    while (!isize % 2));

    if ((pinumber = int *)malloc(isize * isize * sizeof(int)))null)

    isize - 1;

    isize / 2;

    j = isize * isize;

    for (i = 0; i < j; i++)pinumber + i) =0;

    - Initialize ---

    for (i = 1; i <=j;+i) *-Processing module ---

    for (i = 0; i < j;+i) *-Print the result ---

    free(pinumber);

    return 0;

Related questions
18 answers2024-05-17

Indeed, this ** amount is not something that can be done by dozens of lines, it belongs to commercial applications, so let's spend money to buy it.

13 answers2024-05-17

adjoint matrix of a.

Same. Adjoint matrices of diagonal matrices (denoted m) similar to a. >>>More

8 answers2024-05-17

<> take point C as the research object. Subjected to three forces. The Cb direction is the tensile force Mg, and the CE direction is the resultant force of the Cb tensile force and the AC tensile force FCEfce=m again'g.Thereafter, the FCE remains unchanged. The above three forces make up the blue vector triangle cef >>>More

17 answers2024-05-17

Excluding the weight of the object: f(x)=f*fcos30°=f(y)=p-f*sin30°=30kn >>>More

17 answers2024-05-17

The answer is 5 times the root number 2 Newton.

Process Because of equilibrium, a force other than the force of 5n of rotation can be regarded as a force of magnitude 5n, and the direction is opposite to the force of rotation, and after rotation, it becomes a combination of two forces of magnitude of 5n perpendicular to each other, and then the force is combined. >>>More