913 - Joana and the Odd Numbers(UVA)
Run brute force , you'll get elements like below:
Line
0------------- 1
1------------- 3 5 7
2------------- 9 11 13 15 17
3------------- 19 21 23 25 27 29 31
4------------- 33 35 37 39 41 43 45 47 49
Notice carefully : last element in each line propagates though the sequence given below :
6 (7-1)
10 (17-7)
14 (31-17)
18 (49-18)
You need to iterate propagation N /2 (number of lines) times
If you face any problem handling the code you may see the code given below:
#include<bits/stdc++.h>
Line
0------------- 1
1------------- 3 5 7
2------------- 9 11 13 15 17
3------------- 19 21 23 25 27 29 31
4------------- 33 35 37 39 41 43 45 47 49
Notice carefully : last element in each line propagates though the sequence given below :
6 (7-1)
10 (17-7)
14 (31-17)
18 (49-18)
You need to iterate propagation N /2 (number of lines) times
If you face any problem handling the code you may see the code given below:
Comments
Post a Comment