【数学】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 ...
随机推荐
- hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)
#1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...
- Java命令行解析:apache commons-cli
http://commons.apache.org/proper/commons-cli/usage.html Apache Commons CLI用于解析命令行选项,也可以输出详细的选项说明信息. ...
- nginx开启日志,指定格式,查看执行时间
nginx配置: access_log on; log_format access '$remote_addr – $remote_user [$time_local] "$request& ...
- Image模块
1.创建一个新的图片 Image.new(mode,size) Image.new(mode,size,color) 2.层叠图片 层叠两个图片,img1和img2,alpha是一个介于[0,1]的浮 ...
- servlet中service() 和doGet() 、doPost() 学习笔记
Sevlet接口定义如下: 与Sevlet接口相关的结构图: service() 方法是 Servlet 的核心.每当一个客户请求一个HttpServlet 对象,该对象的service() 方法就要 ...
- 软件测试基础homework2
1.for循环里的i>0应该改为i>=0 test1:x=[3,2,5];y=2 test2:x=[3];y=2 test3:x=[2,3,5];y=4 2.for循环里的i应该倒序 te ...
- PostgreSQL ROW_NUMBER() OVER()
转自:http://blog.csdn.net/luojinbai/article/details/45078809 语法: ROW_NUMBER() OVER( [ PRITITION BY co ...
- Android 基于Android的手机邮件收发(JavaMail)之二( Welcome.java 和 ReceiveAndSend.java )
周末休息,这次我们继上次内容继续.上一篇内容我们讲述的是一些准备工作.下载两个javamail.jar和activation.jar文件,然后再BuildPath~ 言归正传,为了展示效果,在这里我申 ...
- 可爱的Python_课后习题_CDay0 时刻准备着!发布
请根据软件发布的流程和软件开发的编码规范,将读者在前面章节所写的程序修改并发 布出去.另外,可以查找下除了 epydoc 外还有哪些较好的 py 文档生成器? pydoc是Python自带的模块,主要 ...
- C# ASP.NET MVC 图片盗链 加水印 的问题
ImageClass using System; using System.Collections; using System.IO; using System.Drawing; using Syst ...