1. Odd rank cube array n = 2 * m + 1 (M =, 3 ,......)
The layout rule is:
A. Place 1 in the middle column of the first row of the N * n matrix, that is, the position is (1, (n + 1)/2 );
B. The number of rows in the last one is less than the number of rows in the previous one. If the number of rows is 0, the number of rows is N;
C. The number of columns stored in the last batch is 1 higher than that of the previous batch. If the number of columns is n + 1, the number of columns is 1;
D. If the former number is a multiple of N, the number of columns in the latter number remains unchanged, while the number of rows increases by 1. 1 Class Magic
2 {
3 [Stathread]
4 Static Void Main ( String [] ARGs)
5 {
6 // Odd rank cube array
7 Int N = 7 ;
8 Int [,] Magicd = New Int [N, N];
9 Int X = 0 , Y = (N + 1 ) / 2 - 1 ;
10 For ( Int I = 1 ; I <= N * N; I ++ )
11 {
12 Magicd [x, y] = I;
13 If (I % N = 0 )
14 {
15X++;
16}
17 Else
18 {
19X--;
20Y++;
21}
22 Check ( Ref X, Ref Y, N );
23 }
24 For ( Int I = 0 ; I < N; I ++ )
25 {
26 For ( Int J = 0 ; J < N; j ++ )
27 {
28Console. Write (magicd [I, j]. tostring ()+ "\ T");
29}
30 Console. writeline ( "" );
31 }
32 Console. Readline ();
33 }
34
35 Private Static Void Check ( Ref Int X, Ref Int Y, Int N)
36 {
37 If (X < 0 )
38 {
39X=N- 1;
40}
41 Else If (X > N - 1 )
42 {
43X= 0;
44}
45 If (Y < 0 )
46 {
47Y=N- 1;
48}
49 Else If (Y > N - 1 )
50 {
51Y= 0;
52}
53 }
54 }
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service