Today I've solved another
Codeforces round, with very disappointing results. That was even more disappointing given the fact that the
problems were very nice (and they are always both in Russian and English there - no excuse for you not to participate in the next round on Friday :)), and I was able to see the solutions quickly.
Two of my five solutions failed. The first one, for
problem B, had this bug (here's a
link to full solution):
036 | if (bx < 0 || bx * by > hblock * wblock || (bx * by == hblock * wblock && bx < hblock)) { |
Line 36 must have "
bx > hblock" instead of "
bx < hblock": this is an implementation of the tie-breaker which asks us for minimal value, not maximal value.
The second one, for
problem E, had this bug (here's a
link to full solution):
067 | double rc = Math.min(ra + Math.PI / 2, rb); |
The condition in line 70 must be "
rc > rb - EPS" or "
ra + Math.PI / 2 > rb + EPS" instead of "
rc > rb + EPS". This code iterates over two sets of segments, and needs to advance one of the pointers based on which segment ends first. I've even had the correct condition with "
- EPS" in the beginning, but has found that this would shift pointer b in case of a tie. For some reason, I've decided that it's better to shift a instead to be on the safe side (now I realize it doesn't matter) - but changed the code in such a way that it will always shift pointer a!
What do you think is the best way to find such bugs during the contest or to not make them in the first place? I used to do the latter automatically, it looks like I need to improve in this area.