【数学】Matrix Multiplication
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 18173 | Accepted: 3912 |
Description
You are given three n × n matrices A, B and C. Does the equation A × B = C hold true?
Input
The first line of input contains a positive integer n (n ≤ 500) followed by the the three matrices A, B and C respectively. Each matrix's description is a block of n × n integers.
It guarantees that the elements of A and B are less than 100 in absolute value and elements of C are less than 10,000,000 in absolute value.
Output
Output "YES" if the equation holds true, otherwise "NO".
Sample Input
2
1 0
2 3
5 1
0 8
5 1
10 26
Sample Output
YES
Hint
#include<iostream>
#include<cstring>
#include<cstdio>
#include<time.h>
#include<stdlib.h>
using namespace std;
inline int read(){
int x=0,f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=getchar()) x=x*10+c-'0';
return x*f;
}
int A[501][501],B[501][501],C[501][501];
int N;
int Num[1001],Num2[1001];//压缩后的A*(B*V) 压缩后的V*C
int Fk[1001];//向量V
int tmp;
int main(){
N=read(); for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
A[i][j]=read();
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
B[i][j]=read();
for(int i=1;i<=N;i++)
for(int j=1;j<=N;j++)
C[i][j]=read(); for(tmp=1;tmp<=60;tmp++){
memset(Fk,0,sizeof(Fk));
memset(Num,0,sizeof(Num));
memset(Num2,0,sizeof(Num2));
for(int j=1;j<=N;j++) Fk[j]=(rand()*rand()+rand())%2;//随机
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
Num[j]+=C[j][k]*Fk[k];//压缩C*V
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
Num2[j]+=B[j][k]*Fk[k];//压缩(B*V)
for(int j=1;j<=N;j++) Fk[j]=Num2[j],Num2[j]=0;
for(int j=1;j<=N;j++)
for(int k=1;k<=N;k++)
Num2[j]+=A[j][k]*Fk[k];//(B*V)*A
int L=1;
for(L=1;L<=N;L++)
if(Num[L]!=Num2[L]) break;
if(L<=N) break;
} if(tmp<=60) cout<<"NO";
else cout<<"YES";
}
【数学】Matrix Multiplication的更多相关文章
- 数学(矩阵乘法,随机化算法):POJ 3318 Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17783 Accepted: ...
- hdu 4920 Matrix multiplication bitset优化常数
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- 矩阵乘法 --- hdu 4920 : Matrix multiplication
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- hdu4920 Matrix multiplication 模3矩阵乘法
hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 ...
- acdeream Matrix Multiplication
D - Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...
- HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵
Matrix multiplication Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/ ...
- Matrix multiplication hdu4920
Problem Description Given two matrices A and B of size n×n, find the product of them. bobo hates big ...
- HDU-4920 Matrix multiplication
矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的.神奇小代码. Matrix multiplication Time Limit: 4000/2000 MS (Java/Ot ...
- hdu 4920 Matrix multiplication(矩阵乘法)2014多培训学校5现场
Matrix multiplication Time ...
随机推荐
- *HDU3486 RMQ+二分
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- 兼容IE浏览器的js浏览器全屏代码
众所周知,IE是个奇葩的浏览器,但是由于用户量很大,开发者还是不得不为IE考虑一下,于是,各种浏览器相关的操作,都要多一个特别的判断——专门针对IE浏览器的判断,这里的全屏也不例外.看代码: func ...
- [转载] Ubuntu 16.04 LTS 一键安装VNC
安装 X11VNC: sudo apt install x11vnc -y 配置访问密码: sudo x11vnc -storepasswd /etc/x11vnc.pass 创建服务: vi /li ...
- ios中自定义tableView,CollectionView的cell什么时候用nib加载,什么时候用标识重用
做了一段时间的iOS,在菜鸟的路上还有很长的路要走,把遇到的问题记下来,好记性不如烂笔头. 在项目开发中大家经常会用到tableView和collectionView两个控件,然而在cell的自定义上 ...
- 宿主机远程桌面连接vmware中的虚拟机
参考了:http://jingyan.baidu.com/article/3052f5a1e8c56397f21f8674.html 感谢~ 宿主机安装了vmware,vmware中安装虚拟机,怎 ...
- java中分页效果的实现代码
首先是将分页所需的一些个资源 ,抽象出一个javabean对象-PageBean: 先把需要分页的数据或是记录都查询出来 存入一个集合类里如List或是Vector, 然后利用其sublist(int ...
- notepad++快捷键大全
Ctrl+C 复制 Ctrl+X 剪切 Ctrl+V 粘贴 Ctrl+Z 撤消 Ctrl+Y 恢复 Ctrl+A 全选 Ctrl+F 键查找对话框启动 Ctrl+H 查找/替换对话框 Ctrl+D 复 ...
- spring boot + gradle[草稿]
入门文档:https://github.com/qibaoguang/Spring-Boot-Reference-Guide 安装gradle 官方下载 https://gradle.org/grad ...
- css控制段落
<p></p>标签:一段话或者段落适宜于用p标签: 段落缩进:text-indent:50px: 文字方向:text-align:center居中.left往左显示.right ...
- BI实施过程中的工具与服务
成功的BI项目,不仅仅是应用了BI工具软件,还要具备完善的BI服务体系,才能称之为真正成功的商业智能bi项目. 现在的BI(商业智能)比起几年前的ERP一样,成为CIO们关注的焦点.在ERP等基础信息 ...