| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 10244 | moocFinal4_高維度稀疏向量 |
|
| 11830 | Play cards 2 |
|
Description
輸入兩個向量,計算向量內積值。
兩個向量的內積,是各項相乘然後加總。例如 [1,2,3] 和 [4,5,6] 內積是 1*4+2*5+3*6 = 32
我們考慮高維度的稀疏向量,也就是大多數的元素都是零,只有少數不為零。資料的表示方式如下
dim1: value1 dim2: value2 dim3:value3 … 0:0
最後以 0:0 結束。例如
向量 [0,5,0,0,9,0,0,33] 是一個 8 維向量,可表示成
2:5 5:9 8:33 0:0
值為0 的維度都可以忽略不需描述,只需記錄非零的維度。利用上述的表示法,讀取兩個向量,然後算出它們的內積。
Input
輸入兩行,分別對應到兩個整數向量。
向量維度最高不超過 2 的 31 次方。記憶體用量不超過 32 MB。每一行都是以 0:0 結束
Output
內積值
最後記得換行
Sample Input Download
Sample Output Download
Tags
Discuss
Description
Niflheimr is playing cards again!
One day, one of his friends, Ken, suspect that Niflheimr was cheating while shuffling cards. Fortunately, Niflheimr records all the operations he did while shuffling cards, so he wants to undo those operations step by step to find out the original card stack. As an intellegent CS student, let's write a program to help Niflheimr prove his innocence!
Input
- 1 ≤ n, m ≤ 104
- Number on cards are non-negative integer and do not exceed 107
- In each operation, card with index = a+b-1 always exists.
Output
Print out the original card stack from top (index 0) to buttom (index n-1), each number occupies one line.