This article describes how to implement the third-level magic square algorithm in JavaScript ~ 9 fill in the 9 different integers in a 3 #215; 3 table, so that the sum of numbers on each row, column, and each diagonal line is the same. For more information, see
Puzzles
Level 3 magic. Try 1 ~ 9 fill in the nine different integers in a 3 × 3 table, so that the s
// Huangfang. CPP: defines the entry point for the console application. // # include "stdafx. H "Void setvalue (unsigned char * HF, int howmuch, int X, int y, unsigned char value) {// fill in the magic square matrix * (HF + (Y-1) * howmuch + (X-1) = value;} unsigned char getvalue (unsigned char * HF, int howmuch, int X, int y) {// fill in the Magic
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
Level n odd magic square
/* Level 3 matrix3*3 matrix, with a constant value (15)Analysis:Create a 3*3 two-dimensional array a [3] [3], assign num = 1 to a [0] [1], and save its subscript, the value in the upper-right corner of a [0] [1] is equal to num ++, which loops in sequence,The subscript will definitely be out of the range.Int ki = (I-1 + 3) % 3;Int kJ = (J + 1) % 3;It can be solvedIf an element exis
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 bright spot is the design of recursive function getpermutation, in the end, several non recursive algorithms are given.
Recursive algorithm,
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
Print the Magic square
Enter a natural number N (2≤n≤9), which requires the output of the following magic square, that is, the length of the n*n, the element value is 1 to n*n,1 in the upper left corner, in turn, in the clockwise direction of the elements. When n=3:
1 2 3
8 9 4 7 6 5
Input f
Noip Raise the group D1T1, has seen several times the question. But drag and drop, causing drag until today to AC off the topic.It seems that there is really nothing to say about this problem, it is the details.First the array must be initialized to 0, and then remember to continue.#include using namespacestd;inta[ A][ A],n;intMain () {Std::ios::sync_with_stdio (false); CIN>>N; inty= n/2+1, x=1; A[x][y]=1; for(intI=2; I i) { if(x==1 Y! =N) {x=N; ++y; A[x][y]=i; Continue; } if(Y==n
The method may be a bit stupid, take the first outer ring (1-12), and then the Middle (13-18) of the sorting method, so that the first pruning as far as possible to cut off three sums, and then remove four sum.But with arrays only, checking for repetition seems like a difficult thing to do, and the 12 results are actually one, 2 (mirror) *6 (angle)Original code, lhy1024#include Hex Magic square C language
Enter a natural number N (2≤n≤9), which requires the output of the following magic square, that is, the edge length is n*n, the element value is 1 to n*n,1 in the upper left corner, in turn the elements in a clockwise direction. When n=3: 123 894 NBSP;NBSP 765 Input form " reads an integer n from the standard input. Output form Print results to standard output. The output matches the required phalan
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.