0

基本上,我已经定义了一个数组 Tp,它有 150 个位置,增量为 0.01。我还以相同的 0.01 增量定义了一个具有 600 个位置的数组 Dp。我正在尝试编写一个大数组 TpDp ,它将 Tp 和 Dp 数组值的每个组合放入它的两列中,以便 Tp 在第一列中,而 Dp 在第二列中。我不确定如何定义 TpDp[][] 位置以使它们相等,例如(并且在语法上不正确)int TpDp[0][0] = new int [Tp[0]][Dp[0]],.

我可能在这方面有各种错误,但到目前为止,我的设置已经定义了 Tp 和 Dp(A = 150,B = 600,这些分别是 Tp 和 Dp 中的位置数):

int [][] TpDp = new int [A*B][A*B]; //declaring new 2-dimensional array TpDp, size needed for combos 

int i; //iteration counter for Tp

int j; //iteration counter for Dp



for (i=0; i<=A; i++)
{ //i counting through all positions in Tp until exhausts A column options
    for (j=0; j<=B; j++)
    { //j counting through all positions in Dp until exhausts B column options
         TpDp[i][j] = Tp[i], Dp[j]; //This is where I'm not sure how do define TpDp[i][j]
    }
}
4

1 回答 1

0

The representation you have now is best.

First of all, you would need to roll your own data representation to fit the values into an array. Second of all, the array would be enormous. Third of all, the enormous array wouldn't do anything more than the 2 seperate arrays you already have, so it would be all cost and no benefit.

From a lookup standpoint: Either way, you would need to do two lookups. Currently you do one lookup from one array and another from a second array. The other way, you'd need to do one lookup in one dimension, then another in the second dimension.

From a memory standpoint: Your quantities are 32 bit values. You store 150 + 600 of them, which totals 3000 bytes. The other way, you would need 150 * 600 values 64 bits wide (to store both numbers), which is 720000 bytes (about 0.4% efficient compared to the current method).

From a time standpoint: both lookups would take the same amount of time.

From a data standpoint: the second way would have a huge amount of redundant data, and the first way stores each necessary value once.

于 2012-07-25T16:33:33.283 回答