views:

135

answers:

2

If the title is completely misleading/unclear please suggest something relevant and better.

Consider a situation where:

Candidate A gets a total of Ta votes from N constituencies, with distribution: {a1, a2, a3 .. aN}

Candidate B gets a total of Tb votes (Ta and Tb are unrelated, which means Ta < Tb, Ta = Tb & Ta > Tb are all possible) from M constituencies (IMP: M <= N), distribution unknown.

What is the best approach to allot the Tb votes to the constituencies b1, b2, b3.. bM such that, they are distributed in the same ratio as a1, a2, a3.. aN.

Some Cases:

1.Ideal

Ta = 20 (8,6,4,2) Tb = 10

Then we get: Tb (4,3,2,1)

2.Somewhat less ideal Ta = 20(8 ,6, 4, 1 , 1) Tb = 10

Then we get (4, 3, 2, 1, 0) which actually means (4,3,2,1) (M < N), and is still tolerable.

+1  A: 

One simple solution:

br = ar * (Tb / Ta)

Which doesn't really work for complex ranges or for a mis-matched Ta and Tb

Like, Ta = 22 (5, 5, 4, 2, 1, 1, 1, 1, 1, 1) and Tb = 7

UPDATE: I followed following rules to get to the best solution:

  1. Keep the ratio as (Tb / Ta) and keep on distributing until you run out.
  2. Whenever you round, round up i.e. 3.24 -> 4 and 3.68 also -> 4
  3. e.g. Here: b1 = 5 * 7 / 22 => 2, b2 = 5*7/22 = 2, b3 = 4*7/22 = 2, b4 = 1 (Since just one remains)

So we have Tb = 7(2,2,2,1) Which is closest to (5, 5, 4, 2)

Swanand
What do you mean by complex ranges?
ShreevatsaR
+1  A: 

Is your a_i sorted always? Assuming that's the case, one way to start is to start assigning b_i from the first value of a_i.

Guru
Yes. That's what I am doing, I'll update the answer..
Swanand