with postfix ++ , you create a temporary object per iteration in loops(that hits performance) which it doesn’t happen with prefix .

check the operator overloading for classes.

btw, thanks for the solution. ]]>

I was initializing the `min’ variable to a wrong value(number of candidates minus one instead of number of ballots minus minus one): this makes the program enter in an infinite loop, and that’s why I got that LTE message.

As soon as Programmin-Challenges comes back on-line, I’ll try the fixed solution.

Regards,

Matteo

I forgot to post a link to the implementation of the algorithm, and one to both the input and the output I use to test things.

* code: http://pastebin.com/rhqYs1uZ

* input: http://pastebin.com/UU3Af4hh

* output: http://pastebin.com/q3hg5sD1

Regards,

Matteo

I’m stuck with the Time Limit Exceeded, but I don’t understand if it’s a matter of algorithm efficiency, or my program falls inside an infinite loop.

Here are the steps of my solution:

1 count all the votes per candidate

2 find min/max number of votes per candidate

3a if min == max then all the remaining candidates have tied, and they are all winners. Then exit.

3b else if max/tot > 50 / 10 we have a single winner. Then exit.

3c find all the ballots starting with a losing candidate and shift the ballot until the head candidate is still in race for winning

4 come back to #1

This is the general idea (obviously we can avoid to count the votes at each iteration and also to shift the ballots).

What do you think about this? Do you see any point of failure?

Thank you so much.

Regards,

Matteo