Thread: help me

  1. #1
    Registered User
    Join Date
    Apr 2010
    Posts
    4

    help me

    Magic Quadrant
    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

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What have you tried?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    Quote Originally Posted by laserlight View Post
    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; 
            )
    Last edited by Salem; 04-14-2010 at 12:42 PM. Reason: Your single FREE code tags edit - learn to use them yourself from now on

  4. #4
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    This algorithm must be a person student algorithms to solve it

  5. #5
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  6. #6
    Registered User
    Join Date
    Apr 2010
    Posts
    4
    what??????

  7. #7
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    this!!!!!!
    /* 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;
    }
    Much easier to read, thus much easier to get read and maybe a reply.
    Last edited by MK27; 04-14-2010 at 10:50 AM.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by subzero View Post
    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?

Popular pages Recent additions subscribe to a feed