[Help] Need some explanations
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: [Help] Need some explanations

  1. #1
    Join Date
    Oct 2012

    [Help] Need some explanations

    i dont get what i need to do here....actualy i dont get anything here....plz explain in normal english what are they telling me...i dont get the sequance either....ai=a0 and etc. thanks beforehand.....realy need explanations for this.....

    Name:  Untitled.jpg
Views: 117
Size:  90.9 KB

  2. #2
    Join Date
    Jan 2010

    Re: [Help] Need some explanations

    Well, it's not terribly complicated, you just need to read it carefully (math freaks you out?), and maybe work it out a bit on paper.

    Basically, your program should calculate a sequence of numbers, according to a formula, and find the largest one among them. It takes a TXT file as input; in the file, each line represents the maximum index, n, for the sequence (note that the sequence itself has n+1 numbers in it). The program runs for each line (that is, for each n), finds the corresponding largest number, and writes a line to the Output.txt file.

    So, the sequence is, in abstract terms: a[0], a[1], a[2], ..., a[n]. The i that appears in the text up there is the index (just like for an array in a for loop: a[i]).

    Next, you have a recursive definition of the sequence, which tells you how to actually calculate the numbers; the first two elements are known:

    a[0] = 0
    a[1] = 1

    Then it says - for each number i, here's how to calculate the elements at indices (2*i) and (2*i + 1):

    a[2*i] = a[i]
    a[2*i + 1] = a[i] + a[i + 1] ____ --> that is: a[i] + the next one

    which really means:

    a[even index e] = a[e/2]
    a[odd index o] = a[(o-1)/2] + the next one

    and so on, until you get to a[n].

    For example:
    i:       a:
    0        0   (given)
    1        1   (given)
    2        1   (same as a[1])
    3        2   (a[1] + a[2])
    4        1   (same as a[2])
    5        3   (a[2] + a[3])  <--- it's the largest number
    So, you calculate all the required numbers (n+1 of them) one way or another, storing each in an array, or better yet, in a List<T>, and then find the largest number, and write it out to a file.
    Then you go onto the next n from the input file, if any.

    You can have an iterative or a recursive solution, whichever suits you better.
    Last edited by TheGreatCthulhu; October 20th, 2012 at 09:42 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Azure Activities Information Page

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


HTML5 Development Center