English 中文(简体)
快速计算得出最低数额?
原标题:fast calculation to get the minimum sum?
  • 时间:2012-05-01 11:36:20
  •  标签:
  • sum

I have a data like this

row1: x1 x2 x3... xn, y1,y2,...yn
row2: x2,x3,....xj, y4,y5,...ym
.....
row 1 million, x6,x2,x7...xk, y2,y3,...yl

每一行各有100万甚至100万。

每一行中,一定数量的x或 y能够具有同样的价值。 如同第1行和第2行一样,共有x2。

my goal is to find which row give me the smallest sum of x 以及 y. for example the sum of row 1 is sum(x1+x2,..+xn+y1+y2+...yn).

The exhaustive way can work but will be very slow since there will be one million * one million operations, I believe there are some clever ways to work.

Thanks

最新情况:

事实上,上述问题源自一个矩阵分部分:提供低于5x5的矩阵

1 2 3 4 5
2 3 4 5 6
2 3 4 5 8
9 1 2 3 5
1 5 2 5 6

there are at least five ways to partition this matrix into two submatrix , for example,

1 2 | 3 4 5
2 3 | 4 5 6
----+------
2 3 | 4 5 8
9 1 | 2 3 5
1 5 | 2 5 6

我有两个子矩阵

1 2
2 3

以及

4 5 8 
2 3 5
2 5 6

so actually 1 2 2 3 is the x I refer, 以及 4 5 8 2 3 5 2 5 6 are the y I mention. so each row is a kind of splitting in the matrix. I am not sure I am clear or not? please add comments.

问题回答

从我前面看到的情况来看,这两行中的x和形态重叠,因此提供了一份名单({x1, x2, ......xn}和{y1, y2, . ym}。

i,j,k,l in (1, n)

页: 1

第1行是:{轴、轴+1, ......,xj }{, yo+1, ......, yp }

第2行是:{xk, xk+1, ......,xl }{ yq, yq+1, ......, yr }

so what you really need to find is the difference between the rows and compare that, and only sum that up since the overlap (part that has the same values) will have the same sum.

你能够告诉我们这两个名单吗? 它们是分类的? 你们知道,X和y名单是独立于各行的吗? ×清单中是否有价值出现在 y清单上? 是否以任何方式分类?

了解这些事情会更快地显示你们需要的东西。

如果没有的话,你将不得不步行,确定重叠之处。

最新情况:

this assumes we only decompose thru the diagonal but you can generalize the algorithm to do others.

Using your example above lets see if we can work it, I am grouping the numbers by x and y sets.

Row 1: {1}{3 4 5 6 3 4 5 8 1 2 3 5 5 2 5 6}
Row 2: {1 2 2 3} {4 5 8 2 3 5 2 5 6} so we added to x {2 3} from the second column and {2} from the second row.
we removed from y {3 3 1 5} from the second column and {4 5 6} from the second row
Row 3: {1 2 3 2 3 4 2 3 4}{3 5 5 6} so we added to x {3 4 4} from the third column and {2 3} from the thrid row.
we removed from y {4 2 2 } from the thrid column and {5 8} from the third row

Note I did not calculate the total sum. just the differences from row 1

如果我们对除1外的每行都进行概括。 (如果你不需要总金额,则根本不计算第1行)

a) for

delat row 1 = 0;

页: 1

i=1至i <= r,j=1至j < r(因此,我们没有两次计算在内)

Delta row r = Delta row (r-1) + sum M(r, i) + sum M(j, r) - sum M(r, n-i) - sum M(n-j, r)

少于第1行的席位将是负数。 你们可以把你们看到的最小的row子保留下来,你们知道哪一笔钱是最低的。

这是否有意义?





相关问题
Linq - 2 tables - Sum

Asiento ******** Id_Asiento integer key Fecha date It_Asiento ********** Id_Asiento integer Forenkey Importe float I wan to do This SQL Query with Linq select Asiento.Id_Asiento, ...

SELECT command to calculate percentage

I m trying to get the percentage of each video I have in my database based on its view count against all other videos. I m then trying to display all the videos from highest view count to lowest, ...

Sum values of a loop

<% @pid = item.producto_id %> <br/> Producto: <%= Producto.find_by_id(@pid) %><br/> Costo de Compra: <%= @costo_de_compra = Producto.find(:all, :conditions => "id = #{@...

Sum and Division example (Python)

>>> sum((1, 2, 3, 4, 5, 6, 7)) 28 >>> 28/7 4.0 >>> sum((1,2,3,4,5,6,7,8,9,10,11,12,13,14)) 105 >>> 105/7 15.0 >>> How do I automate this sum and division ...

热门标签