51nod-1140-矩阵相乘结果的判断
来源:互联网 发布:淘宝冷光美白仪有用么 编辑:程序博客网 时间:2024/05/21 07:06
题目描述
给出三个N*N的矩阵A, B, C,问A * B是否等于C?
Input
第1行,1个数N。(0 <= N <= 500)
第2 - N + 1行:每行N个数,对应矩阵A的元素。(0 <= M[i] <= 16)
第N + 2 - 2N + 1行:每行N个数,对应矩阵B的元素。(0 <= M[i] <= 16)
第2N + 2 - 3N + 1行:每行N个数,对应矩阵C的元素。
Output
如果相等输出Yes,否则输出No。
样例
input
2
1 0
0 1
0 1
1 0
0 1
1 0
output
Yes
题解
似乎是久违的更新quq
这道题目呢。
n是500,n^3是肯定会爆啦
然后现在这里有一个神奇的定理是矩阵结合律
比如在A*B=C等式两边同乘X矩阵,等式依旧成立
然后就可以把时间复杂度降到n^2了
p党瑟瑟发抖。
var n,i,j:longint; a,b,c:array[0..505,0..505] of int64; ans,sum,x,xx:array[0..505] of int64;begin readln(n); for i:=1 to n do begin for j:=1 to n do read(a[i,j]); readln; end; randomize; for i:=1 to n do x[i]:=random(1000) mod 17; for i:=1 to n do xx[i]:=x[i]; for i:=1 to n do for j:=1 to n do inc(sum[i],x[j]*a[j,i]); for i:=1 to n do begin for j:=1 to n do read(b[i,j]); readln; end; for i:=1 to n do x[i]:=sum[i]; for i:=1 to n do sum[i]:=0; for i:=1 to n do for j:=1 to n do inc(sum[i],x[j]*b[j,i]); for i:=1 to n do begin for j:=1 to n do read(c[i,j]); readln; end; for i:=1 to n do for j:=1 to n do inc(ans[i],xx[j]*c[j,i]); //for i:=1 to n do write(x[i],' '); writeln; //for i:=1 to n do write(sum[i],' '); writeln; //for i:=1 to n do write(ans[i],' '); writeln; for i:=1 to n do if sum[i]<>ans[i] then begin writeln('No'); halt; end; writeln('Yes');end.
好久没更新博客 访问量不增反减???
阅读全文
0 0
- 51nod 1140 矩阵相乘结果的判断(矩阵结合律)
- 51nod 1140 矩阵相乘结果的判断
- 51Nod-1140-矩阵相乘结果的判断
- 51nod 1140 矩阵相乘结果的判断
- 51nod-1140-矩阵相乘结果的判断
- 51nod oj 1140 矩阵相乘结果的判断【矩阵的结合律】
- 51NOD 1140 矩阵相乘结果的判断(随机化算法+矩阵结合率)
- 矩阵相乘的算法
- 矩阵相乘的算法
- 矩阵的相乘
- 矩阵相乘的优化
- 矩阵的逐个相乘
- 矩阵相乘的本质
- poj 3318 随机(矩阵相乘判断)
- 【游戏课】技术片段之——三个矩阵相乘的结果
- 两个矩阵相乘但是结果不对,只有第一行的对,求解!
- 矩阵相乘的快速算法
- 矩阵相乘的最优顺序
- 【python学习笔记】Python对经纬度处理
- 图像卷积、相关以及在MATLAB中的操作 2016年7月11日 20:34:35, By ChrisZZ 区分卷积和相关 图像处理中常常需要用一个滤波器做空间滤波操作。空间滤波操作有时候也被叫做卷积滤
- Generic Views
- mysql使用like查询使用
- JavaEE上传和下载
- 51nod-1140-矩阵相乘结果的判断
- CAD批量转pdf的教程
- 【反序表+树状数组】Codeforces Round #441(Div.2)D[Sorting the Coins]题解
- 深度学习人工智能/大数据/云计算-书籍整理
- 添加路由
- Python 递归
- webstorm快捷键大全(亲自整理)
- ProtoBuffer消息设计经验
- 风险管理方法论和选择审计方法