Hi Toni, I think the problem is that your predicate function must be a 'strict weak ordering'. One of the conditions it must satisfy is that it's irreflexive (i.e. comp( x, x ) == false) and antisymmetric (i.e. comp( x, y ) = !comp( y, x )). There are some other conditions it must observe, for more info see: http://www.sgi.com/tech/stl/StrictWeakOrdering.html and http://www.sgi.com/tech/stl/sort.html
I think your predicate fails to meet these conditions. For instance comp( 3, 3 ) always returns true, so it can't be antisymmetric (it should return false in this case). I know with Visual C++ it will warn if your predicate is badly formed - it will assert if it detects that your predicate function fails to meet the requirements. It might be worth seeing if your environment offers a similar feature. Paul On 23 May 2011 07:31, Sturzu Antonio Gabriel <[email protected]> wrote: > I had the following problem in problem B which may have cost me the > qualification. > > Like many of you in the last part of my algorithm I needed to sort the > distances in decreasing order. Here's what the problem was: > > I used the sort function in STL with the following comparion function: > > bool comp(const long long & a, const long long &b) > { > return a>=b; > } > > This gave incorrect results for the small input. After the contest when I > started looking for the mistake I found that if I replace >= wiht > my code > worked on both the small and the large inputs. From this, I came to the > conclusion that the sort function didn't work properly for the comparison > function implemented with >= but worked with >. How can this be ? Can anyone > enlight me on this ? > > Thanks, > Toni > > -- > You received this message because you are subscribed to the Google Groups > "google-codejam" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/google-code?hl=en. > > -- You received this message because you are subscribed to the Google Groups "google-codejam" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-code?hl=en.
