Hey guys, I have got a C++ competition tomorrow and it is very important for me. Following are few of the questions from past years. Please, please, pleeeasse read them and guide me on how do I solve them so that I get some preparation for tomorrow
Who is going to read through all those links? If you want answer to specific problem, quote it and give proper explanation to what exactly you need help with.
Do you have specific questions concerning these tasks or need complete solution? In the latter case I cannot help. But we can discuss ideas and problems. E.g. under the first link there is a task to compute the maximum size of the audience in the hall given an input data of the following form
N
e1 l1
e2 l2
...
eN lN
where N - nb of noted person, ek and lk - (e)nter and (l)eaving time of k-th noted person to the hall. Task: find the maximum number of persons being in the hall at the same time.
The simplest solution woud be to have a vector (array) of ints, where i-th element corresponds to the i-th minut. Then looping through the input table, on each step, say k-th, we increment elements in the vector with indicies i: ek<=i<=lk. When all the entries are looked up we simply search the maximum in the built vector.
@chasevoid
I didn't quote the problems because they won't fit in as this forum has restriction on the max length.
@poet
Thanks for the reply.
I am not looking for complete answers. I just want to someone to help me as to how should I go about solving the problems.
I thought of the code you provided. But there's a little problem. As far as my calculation goes, this program will require exponential run time. The inputs can go as long as a few thousands. Just imagine the time it would take.
Where do you see an exponential complexity? It's linear under the given assumption on entry and exit time to be in [0, 107], which means that we have at most 108*N+108 evaluation.
good luck then.. anyway in first problem you post why is the answer 4?
Serial No Enters at Leaves at
1 1 7
2 2 4
3 6 9
4 3 8
5 5 10
In this example, the maximum size of the audience during the programme was 4. This
was achieved between time 6 and 7.
anyway in first problem you post why is the answer 4?
because there is no time when all 5 persons were together in the hall (e.g., 2nd and 3rd guys never met) but during 6th and 7th minutes four persons were in the hall: