Magic Square is divided into Class 3 . Odd Order magic square (odd), double even magic square (can be divisible by 4, such as 8,12,16 ...). ), the single magic
+ +;
Col%= N;
}
A[row][col] = i;
}
for (row = 0;row{
for (col = 0;col {
printf ("%6d", A[row][col]);
}
printf ("\ n");
}
return 0;
}
Algorithm 2: Order n = 4 * m (M =1,2,3 ...) ) The laws of the Rubik's Cube are as follows:
By numbers from small to large, that is, 1,2,3......n2 order to the magic square from left to right, from top to bottom to fill;Dividing the
Topic Links:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1835Main topic:Give you an n-order matrix that determines whether n-order magic squares. The numbers used are not necessarily 1~n^2, butThe numbers must not be duplicated.Problem Solving Ideas:According to the definition of magic square, traverse and judge all the rows, vertical lines, oblique
Written in 2012.10:Originally this is rectification that "C Program Design (fourth edition)" of a after class exercises, just start to do when to find the best algorithm on the Internet, the results found that odd and double even (4 multiples) of the case algorithm is relatively simple, But a single even number ( a multiple of 2 but not a multiple of 4) has been unable to find a definite algorithm, even the Baidu Encyclopedia of the explanation of the problem is " because the non-four multiple
http://noi.openjudge.cn/ch0108/22/
Total time limit:
1000ms
Memory Limit:
65535kB
Describe
Magic Square is a very magical n*n matrix, it's each row, each column and the diagonal, plus the number is the same.We can construct a magic squar
) printf ("%5d", A[i][j]); printf ("\ n"); } System ("Pause"); return 0;}Two: Order n = 4 * m (M =1,2,3 ... The law of the even Rubik's Cube is as follows:Numbers from small to large, that is, 1,2,3... n2 order to fill the magic phalanx from left to right, from top to bottom, and divide the magic phalanx into several 4x4 sub-matrices, and take out the elements o
2.1 4 m level
(1) Fill in the numbers 1 to n × n in the matrix from top to bottom and from left to right.
(2) the number of two Diagonal Points in all the 4x4 sub-squares of the square matrix about the square matrix Center for symmetric exchange, that is, a (I, j) and a (n-1-i, n-1-j) switch. The number of all other locations remains unchanged.
/Begin {bmatrix}1
Level Program Design (second edition)" This book has a number of good algorithm examples, they are all written in C, I use C # rewrite, in a small tool to show, so more intuitive.
The first one is to see the P96 on the formation of the magic square.
Rubik's Cube array refers to the elements of the natural number of 1,2,...,n2 nxn square, each element value is
After reading the strongest brain, there is a period of N-order magic cube, as a programmer, my first reaction when I can use the program implementation, here to publish the N (odd) Order magic square Java implementation code:Package Com.lzugis.test;public class Practice {public static int[][] Magicodd (int n) {int[][] square
JavaScript to solve the third-order magic square
Puzzle: Third-order magic Square, try to fill in a 3x3 table with the 1~9 9 different integers, making the sum of the numbers on each row, each column, and each diagonal.
Strategy: Exhaustive search. Lists all the integer fill schemes, and then filters them.
The brigh
Time limit per test
2 secondsMemory limit per test
256 megabytesInput
Standard InputOutput
Standard output
Little elephant loves magic squares very much.
A magic square is a 3 hour x hour 3 table, each cell contains some positive integer. At thatThe sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the
This paper illustrates the method of realizing the odd-order magic square in C language. Share to everyone for your reference. The implementation methods are as follows:
Copy Code code as follows:
#include "stdio.h"
#include "string.h"
#include "Stdlib.h"
#define N 5
void Main () {int a[n][n]={0};int i,j;int k;
i = 0;j = N/2;A[0][j]=1;for (k = 2; k if (i = = 0 J = = N-1) {//First, deter
DescriptionIn a square consisting of several neatly arranged numbers, the sum of the numbers of any row, line, and diagonal in the graph is equal, and a chart of this nature is called the magic square. It has been determined that the N-Order magic Square (n>=3) can construct
Magical Magic SquareTitle DescriptionMagic Square is a very magical n*n matrix: It is composed of digital three-way,......, n*n, and the sum of the numbers on each row, column, and two diagonal lines are the same.When n is an odd number, we can construct a magic square by the following methods:First write 1 in the midd
Anti-Magic Square
China's ancient books are very early records
2 9 4
7 5 3
6 1 8
This is a third-order magic square. Each row and the number on the diagonal are added equally.
Consider one of the opposite questions below.
You can not fill Hu Ci sudoku with 1~9 numbers.
So that the numbers on each diagonal of ea
H-Fantastic phalanxTime Limit: 1000 msDescriptionThe magic is to place the number from 1 to N2 in a n * n matrix. Each number appears only once andFor each row, the sum of each column and its diagonal line is the same.The focus of this problem is the odd magic square, which means that N is an odd number. You will use the following method to constructThe most basi
Puzzles
Third-order magic square. Try to fill in a 3x3 table with these 9 different integers, making the sum of the numbers on each row, each column, and each diagonal 1~9.
Strategy
Exhaustive search. Lists all the integer fill schemes, and then filters them.
JavaScript solution
Copy Code code as follows:
/**
* Created by Cshao on 12/28/14.
*/
function Getpermutation (arr) {
simulation has always been the NOIP must test a type of question is also the most simple type of questions generally speaking, this problem takes the least time and should try to take the most points, so as my "Noip real Problem" series of the first article on first say a simulation problem
Topics① Toy Puzzle "Noip Improvement Group" 2016d1t1 [difficulty]0.8 [tag]② Magical Magic Square "Noip raise Group" 20
Magic Square is also known as Rubik's Cube, square squares or halls. In a square consisting of a number of neatly arranged numbers, the sum of the numbers of any one row, one longitudinal line, and the diagonal is equal, and a chart of this nature, called Magic
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.