# help me

• 04-14-2010
subzero
help me
Magic Square is a square matrix n * n contains the numbers 1 to sqr (n) (each number only once), so that the total numbers of each line separately equals the sum of the numbers of each column; Ende and equal also the total number of each country separately.

First:
Find one of them the following simple way to generate the magic box when the matrix after the individual:
1 - Put 1 in the middle of the line up.
2 - After filling in the box (p, q) test number in the box at the line up and the left column (see arrow in the drawing) any cell (p-1, q-1).
3 - If the box is already busy place the following number of x +1 in the empty box, which lies directly under the box (p, q).
Required:
1 - Type of CheckMagic that tests the fact that the box (ie, matrix) magic or not.
2 - What is the complexity of the CheckMagic.
3 - Write a recursive procedure that you love the magic box of dimension n and in accordance with the algorithm described above.
Procedure RecMagic (x: 1 .. nmax; p, q: 1 .. nmax);
(X represents the number to be filled in and represent each of the p and q are the site that will put the number in it)

Second:
We want to put a general algorithm to solve this issue, regardless of whether it is the matrix after the individual or not, and drawing on the general outline of the algorithms regressive (BackTracking Algorithms).
Required:
4 - Writing a regressive procedure that calculates the magic box of dimension n>
Procedure BackTMagic (x: 1 .. nmax; var b: Boolean);
5 - - type program that you choose the programming language (Java, C #, VB.Net, C + +, Pascal) for the implementation of the algorithm.
That assumes that the Matrix is the matrix required for the convertible in procedural and median x indicates the number that should be put in the matrix and the mediator b indicates the success of the procedure or not.
Note: You must first clarify the call to this procedure
• 04-14-2010
laserlight
What have you tried?
• 04-14-2010
subzero
Quote:

Originally Posted by laserlight
What have you tried?

Wh1-type of CheckMagic that tests the fact that the box (no matrix) magic or not.

To not have the matrix box, so that the number of lines equal to the number of columns
And the total numbers in each line is equal to the total numbers in each column and is equal to the total number of the country and is equal to the hard Magic

Hard = (n * n * n + n) \ 2, where N is the rank of the matrix means the number of lines or columns

The condition here is that we do not repeat the number in the matrix all of Marin

That we have imposed a bilateral matrix size n any number of lines and columns
int rcl [] [] = new int [n] [n];
for (int i = 1; i <= n; i + +)
for (int j = 1; j <= n; j + +)

Enter the data matrix
And grown up a counter to calculate the total number of the line that we enter as well as the total column prepared we are entering
On the assumption that among the total number of the line is d and among the total number of column is fixed and t is the magic symbol th
if (d == th & & t == th & & rcl [i]! = rcl [j +1])

rcl [i]! = rcl [j +1] we want here not to repeat the number twice

Be a magic box or the matrix

else
Is not a magic bullet

2_ What is the complexity of CheckMagic.

Complexity is
Complexity of the complexity of the episode I * The second condition was the last
Means the complexity class will be welcomed
O (N * N)
3 - Write a recursive procedure that you love the magic box of dimension n and in accordance with the algorithm described above.
Procedure RecMagic (x: 1 .. nmax; p, q: 1 .. nmax);
(X represents the number to be filled in and represent each of the p and q are the site that will put the number in it)
Code:

```public int [,] magic_square (int x, int p, int q)         (               int [,] sq = new int [x, x];             int c = 1;             for (int i = p, j = q; c <(x * x) +1; i -, j + +)             (                 if (j == x)                 (                     j = 0;                 )                 if (i == -1)                 (                     i = x-1;                 )                   if (sq [i, j]! = 0)                 (                     i + +; j -;                     if (j == -1)                     (                         j = x-1;                     )                     if (i == x)                     (                         i = 0;                     )                     i + +;                     if (i == x)                     (                         i = 0;                     )                 )                 sq [i, j] = c;                 c + +;             )             return sq;         )```
• 04-14-2010
subzero
This algorithm must be a person student algorithms to solve it
• 04-14-2010
MK27
• 04-14-2010
subzero
what??????
• 04-14-2010
MK27
this!!!!!!
Quote:

/* NOTE FROM MOD: This thread was origanally titled: !! <> Everybody Please Read <> !! *\

This is more addressed to the newer people of this forum, but I think it would be a good refresher for some.

USE CODE TAGS!!!

What are code tags?
They are HTML-Like tags that you can insert into your post and create a specially formatted box for source code.
for example:
Code:

```for (i=0;i<10;i++) {       cout << "hello world" << endl; }```
• 04-14-2010
tabstop
Quote:

Originally Posted by subzero
what??????

I agree.

As to the questions, the English is mangled enough that I'm not quite sure what you have questions on and what you have done. You have the gist of the check algorithm, I think. You've got the complexity. I don't even know what the third question means, so can't help there. Do you mean "recursive" for "regressive"? And even then, you've got a number and a boolean and ... where did your matrix go? And what is this function supposed to do?