Topic: Re: accordion Extension
Hello, Kodt, you wrote: It is given: a dial-up of integer values X  - width of some segments. And target value D - width of a total segment on which we project them so in the total they occupy it all - acquiring values W  (D). Naturally, there are rounding off problems. It is necessary to make it as much as possible beautifully, that is, to observe a row of conditions: Same 1) the Monotonicity: at the monotonous magnification of the total each item too monotonically grow. Certainly, will tell more precisely - do not decrease, because at a total increment on 1 it is clear that this will be given only to any one item.> the bad method W [i] = floor (D*X [i]/sum (X)) already therefore disappears - everything, except last, we give proportional values, approximating downwards> W [last] = D-sum (W [0. last)) - last we give all remained because it rakes up residual in a range (0. . n-1) where n - the amount of elements and as a result skips Besides, is the classical approach: you consider separately value how many it is necessary to select (D*X [i]/sum (X)) and how many it is actually selected. You take a difference (it can be both positive, and negative) memberwise and you call it a deficit. And it is necessary to add always to that element, at which a deficit the greatest. It gives observance both this requirement, and remaining. Well that is from this it is already possible to receive naive implementation. For example, you decompose D = sum (X) * Q + R. The first part sum (X) *Q you arrange directly (there there will be no rounding-off errors). And residual from R you arrange the above-stated method through a deficit (it is a maximum one sorting of elements according to a deficit after initiating allocation).