Rating Points Exchange
Problem B - Rating Points Exchange
Apologies in advance to anyone new to programming contests, who just happened to have this problem as the second ever programming problem they see. Not that it's a bad problem - every contest seems to need at least one messy, fiddly, floating-point-error-prone problem to show that not everything is nice and discrete. Like many other of its type, the problem was basically: using floating point ratings, apply a formula we give you to them, and output the result after doing it many times. Oh, and the formula has about 10 rules. Don't worry, even the World finals has questions like this (although slightly more tricky), in a way it's a good test to see how familiar you are with your language, and pedantic you can be testing.As the algorithm is given in the problem statement, I can't say much, except re-iterate the important point: Don't use floating point numbers when you can avoid them. You'll notice that all calculations in this problem are done in two decimal places - this means you can scale everything up by 100 and deal only in integers. A number of teams no doubt were only off because errors accumulated to get higher than 0.01 (e.g. writing xx.14 instead of xx.15 in the output)
Secondly, when the output instruction is to sort, sort. And if it's to sort equal scores with names descending, then sort descending. While it may seem odd, my guess is the official solution does it similar my final code - that is, sort everything ascending, then print it out in reverse. Also, this is where good library knowledge comes in - in this case, in C++, if you sort pair<>'s, it first sorts them by their first element (in this case, score) using second element as a tiebreaker (in this case, name), exactly what we want.
Code (again, as yet unjudged) can be found here.
Comments
Post a Comment