1
0
mirror of https://github.com/Didnelpsun/CS408.git synced 2026-02-09 21:55:46 +08:00
Files
CS408/Data-Structrue/5-array-ex.md
2021-09-19 23:34:30 +08:00

46 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 数组习题
## 三对角矩阵
**例题** 有一个$100$阶的三对角矩阵$M$,其元素$m_{i,j}$$1\leqslant i,j\leqslant100$)按行优先依次压缩存入下标从$0$开始的一维数组$N$中。元素$m_{30,30}$在$N$中的下标是()。
$A.86$
$B.87$
$C.88$
$D.89$
解:$B$。根据公式$k=2i+j-3$。但是这种公式很难记忆,所以直接找规律。
**例题** 若将$n$阶上三角矩阵$A$按列优先级压缩存放在一维数组$B[1\cdots n(n+1)/2+1]$中,则存放到$B[k]$中的非零元素$a_{i,j}$1\leqslant i,j\leqslant n$)的下标$i$、$j$与$k$的对应关系是()。
$A.i(i+1)/2+j$
$B.i(i-1)/2+j-1$
$C.j(j-1)/2+i$
$D.j(j-1)/2+i-1$
**例题** 若将$n$阶下三角矩阵$A$按列优先顺序压缩存放在一维数组$B[1\cdots n(n+1)/2+1]$中,则存放到$B[k]$中的非零元素$a_{i,j}$$1\leqslant i,j\leqslant n$)的下标$i,j$与$k$的对应关系是()。
$A.(j-1)(2n-j+1)/2+i-j$
$B.(j-1)(2n-j+2)/2+i-j+1$
$C.(j-1)(2n-j+2)/2+i-j$
$D.(j-1)(2n-j+1)/2+i-j-1$
**例题** 设有一个$12\times12$的对称矩阵$M$,将其上三角部分的元素$m_{i,j}$$1\leqslant i\leqslant j\leqslant12$)按行优先存入$C$语言的一维数组$N$中,元素$m_{7,2}$在$N$中的下标是()。
$A.50$
$B.51$
$C.55$
$D.66$