-->
当前位置:首页 > 题库

PROGRAMMING:Sparse matrix addition

Luz5年前 (2021-05-10)题库429
Given two matrices $$a $$and $$B $$, find the sum matrix $$C = a + B $$.
###Input format:
The first row contains two numbers $$row $$and $$col $$, which represent the number of rows and columns of the matrix respectively. The dimensions of $$a $$and $$B $$are consistent.
The second line has only one number $$n_ 1 $, indicating the number of non-zero elements in the next $$a $.
Next comes $$n_ Each line is in the form of $$I / space J / space a [I, J] $, which represents the element $$a [I, J] $, in the $$a $$I / line and $$J / column. In order to be consistent with most programming languages, they all start from zero, that is to say, the effective range of subscript is $$[0, row-1] [times [0, COL-1] $.
In $$n_ After the 1 $$line, there is a number $$n_ 2 $, which represents the number of non-zero elements in the matrix $$B $, and then $$n_ The 2 $$line describes the non-zero elements in $$B $, which are in the same form as the previous description of the non-zero elements in $$a $.
The input of matrix elements follows the row main order. All the input here can be correctly represented by the type of 'Int'. It can be assumed that the input is legal.
###Output format:
Number of elements in the first row output and matrix $$C = a + B $$whose absolute value is greater than $$0.1 $$$$n_ 3 $$, and then $$n_ 3 $$row, output the non-zero elements according to * * row main order * *, followed by the subscript of row and column and the corresponding elements.
###Input example:
```in
2 2
one
1 1 1
one
0 0 1
```
###Output example:
```out
two
0 0 1
1 1 1
```







answer:If there is no answer, please comment