With the N calculated according to your equation 0 <= N < [(X/C)−(a/F)]
I get the correct result (i.e. the same I had with my different solution for both small and large, and both accepted as correct) I tried by calculating the N as follows: either int n = static_cast<int>(floor(X/C - 2.0/F)); or (the more correct) int n = static_cast<int>(ceil(X/C - 2.0/F)) - 1; followed by if (n < 0) n = 0; The ceil() version is "more correct" strictly speaking, as the floor() actually gives N <= [(X/C)−(a/F)], but it does not seem to have any impact (I tried with both, the N only seems to differ in cases where both variants give the same result time) - I initially though that might be your problem, that you might have used floor() and that it would give wrong results in some cases. In any case, it seems that the math is correct in the principle, and just your implementation was not correct, so we'd definitely need to see the code to find the issue. I did similar calculations, except I did not try to calculate the N beforehand, as the computer is pretty good at finding the minimum numerically and the calculations are not so expensive for this particular problem: http://pastebin.com/XUvbG81T -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/86cde615-44bf-42bd-a7b1-796ca474ac14%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
