【数学】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 ...
随机推荐
- HDU 1281 二分图
棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Android 之 ListView的学习
ListView 是一个控件,一个在垂直滚动的列表中显示条目的一个控件,这些条目的内容来自于一个ListAdapter .EditText Button TextView ImageView Chec ...
- javascript学习之带滚动条的图片
之前找了好久没有找到,就自已动手写了一个: <!DOCTYPE html> <html> <head> <meta charset="utf-8&q ...
- 【iCore3 双核心板_FPGA】实验二十五:NIOS II之UART串口通信实验
实验指导书及代码包下载: http://pan.baidu.com/s/1eRMZq18 iCore3 购买链接: https://item.taobao.com/item.htm?id=524229 ...
- C++的动态内存分配
- PARALLEL PROCESSING
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- 安装GIT,集成到Powershell中
1.首先安装GIT http://msysgit.github.io 下载最新版,然后安装.没什么好说的. 装完之后,把 安装路径/bin 加入到环境变量的Path中 2.删除Git的右键菜单 安装完 ...
- Raspberry pi 添加vnc远程桌面控制
// 安装服务 apt-get install tightvncserver // 设置连接密码 vncpasswd // 在端口1处开启服务 tightvncserver :1
- vert.x学习(四),使用模板解析器ClassLoaderTemplateResolver
在vert.x中使用模板解析,可以为我们带来很多方便.我这里学习了一下ClassLoaderTemplateResolver的简单使用.这次工程配置与上篇一样,不需要做任何多的配置.直接编写代码就可以 ...
- 有关windows系统的EXE和DLL文件说法错误
正确答案: B C 你的答案: C (错误) EXE和DLL文件都是PE文件 EXE不能有导出函数,DLL可以有导出函数 EXE有x86和x64之分,则DLL没有 EXE可以单独运行,DLL则不行 ...