October 20th, 2012, 06:42 PM
[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.....
October 20th, 2012, 09:34 PM
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, a, a, ..., 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
a = 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].
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.
0 0 (given)
1 1 (given)
2 1 (same as a)
3 2 (a + a)
4 1 (same as a)
5 3 (a + a) <--- it's the largest number
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
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!