Round Numbers
Input : array of decimals ~ X
Output : array of int ~ Y
But they need to satisfy the condition:
sum(Y) = round(sum(x))
minmize (y1x1 + y2x2 + … + ynxn)
Example 1:
input = 30.3, 2.4, 3.5
output = 30 2 4Example 2:
input = 30.9, 2.4, 3.9
output = 31 2 4
Solution
Select one round
direction and then make up for the gap between the current sum and its original round sum.
If we select floor
then the gap will be made up by the ceiling
.
Note The biggest gap between the floor and original number is the smallest gap between the ceiling and original numbers.


Always welcome new ideas and practical
tricks, just leave them in the comments!