搜索
首页 电脑/网络 程序设计 C/C++

矩阵乘积(利用文件操作)

    已知三个矩阵A,B,C,这三个矩阵中大多数元素为0,我们称之为稀疏矩阵。因此我们采用三元组<i,j,a>来表示矩阵第i行第j列的值为a,其他未列出元素为0;在计算机中,我们仅给出非零元素的三元组,而且是用行优先法给出稀疏矩阵的三元组,首先是第一行按列给出,然后是第二行。
  。。。例如,矩阵 [1 0 0 0] [0 0 2 -1] [0 1 2 3] [0 0 0 0]那么其三元组为:1 1 12 3 22 4 -13 3 23 4 3你的任务就是:编程完成计算D=A*B*C数据输入:1。
   文件输入第一行为:x y(第一行为两个正整数:x,y分别表示输出结果所在行与列)第二行为:m n o p(第二行给出的正整数表明A为m*n矩阵,B为n*o矩阵,C为o*p矩阵)第三行为:i j a(第三行以后每一行有三个整数分别是矩阵的三元组表示法中的一个元素的值,每个矩阵间有一个空行。
  表示的顺序是矩阵A B C)。。。。。。注:1<=m,n,o,p<=6000,三元组总个数不超过6000。数据间用空格分开。2。输出文件:为D=A*B*C的第x行y列的值示例:input。txt1 1 1 output。txt12问题补充:1。题中的例子是一个4*4的矩阵,只是给出三元组的写法2。
  请给出程序实现,最好是c++语言,c也行。

全部回答

2006-04-12

0 0
    #include typedef struct { int row; int column; float *m; } Matrix; bool Multiply(const Matrix &m1, const Matrix &m2, Matrix *result) { if ( lumn != w) return false; int i, j, k; for (i=0; im+i* lumn+j) += *(m1。
    m+i* lumn+k) * *(m2。m+k* lumn+j); return true; } bool Evaluate(Matrix &m1, const Matrix &m2) { if ( w!= w || lumn!= lumn) return false; for (int i=0; i>n>>m>>mat[0]。
    row>>mat[0]。column>>mat[2]。row>>mat[2]。column; n--; m--; mat[1]。
  row = mat[0]。column; mat[1]。column = mat[2]。row; mat[3]。row = mat[0]。  row; mat[3]。
  column = mat[2]。column; w = mat[0]。row; lumn = mat[1]。column; for (i=0; i>i>>j; i--; j--; fin>>mat[k]。
    m[i*mat[k]。column+j]; t(ch); t(ch); if (ch == '\n') k++; else ekg(-1, ios::cur); } Multiply(mat[0], mat[1], &tmp); Multiply(tmp, mat[2], mat+3); fout<<mat[3]。
    m[n*mat[3]。column+m]<<endl; for (i=0; i<4; delete[] mat[i++]。m); return 0; } 。
  

2006-04-09

39 0
我一直就Mathematica编。分分钟搞定。

类似问题换一批

热点推荐

热度TOP

相关推荐
加载中...

热点搜索 换一换

电脑/网络
C/C++
硬件
电脑装机
程序设计
互联网
操作系统/系统故障
笔记本电脑
反病毒
百度
软件
程序设计
C/C++
VB
数据库
汇编语言
JAVA相关
VC++
C#/.NET
其他编程语言
C/C++
C/C++
举报
举报原因(必选):
取消确定举报