http://www.spoj.com/problems/MRECAMAN/
This task can be solved easily with the help of C++ STL map (for more info about using map go here). The problem could have been done easier if there wasn't the requirement for the numbers being distinct we could have solved it easily but we need to keep the numbers distinct, this is where C++ STL map template helps us, in every step when we are calculating the current element we need to push it in the map and mark it as true. It is impossible to do with the old fashioned method, keeping a big boolean array and mark every number in it because the numbers are very big no computer would be able to hold an array of elements that big.
This task can be solved easily with the help of C++ STL map (for more info about using map go here). The problem could have been done easier if there wasn't the requirement for the numbers being distinct we could have solved it easily but we need to keep the numbers distinct, this is where C++ STL map template helps us, in every step when we are calculating the current element we need to push it in the map and mark it as true. It is impossible to do with the old fashioned method, keeping a big boolean array and mark every number in it because the numbers are very big no computer would be able to hold an array of elements that big.
No comments:
Post a Comment