http://poj.org/problem?id=3318

矩阵A*矩阵B是否等于矩阵C

 #include <cstdio>
#include <cstring>
#include <time.h>
#include <algorithm>
#define maxn 1010
using namespace std; int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn],d[maxn];
int n;
int b1[maxn],c1[maxn],a1[maxn]; int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
scanf("%d",&a[i][j]);
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
scanf("%d",&b[i][j]);
}
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
scanf("%d",&c[i][j]);
}
}
srand((unsigned int)time());
for(int i=; i<n; i++)
{
d[i]=rand()%;
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
b1[i]+=b[i][j]*d[j];
c1[i]+=c[i][j]*d[j];
}
}
for(int i=; i<n; i++)
{
for(int j=; j<n; j++)
{
a1[i]+=a[i][j]*b1[j];
}
}
bool flag=false;
for(int i=; i<n; i++)
{
if(a1[i]!=c1[i])
{
flag=true;
break;
}
}
if(!flag) printf("YES\n");
else printf("NO\n");
}
return ;
}

poj 3318 Matrix Multiplication的更多相关文章

  1. Poj 3318 Matrix Multiplication( 矩阵压缩)

    Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 18928   Accepted: ...

  2. 数学(矩阵乘法,随机化算法):POJ 3318 Matrix Multiplication

    Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17783   Accepted: ...

  3. [poj 3318] Matrix Multiplication (随机化+矩阵)

    Description You are given three n × n matrices A, B and C. Does the equation A × B = C hold true? In ...

  4. POJ 3318 Matrix Multiplication(随机算法)

    题目链接 随机算法使劲水...srand((unsigned)time(0))比srand(NULL)靠谱很多,可能是更加随机. #include <cstdio> #include &l ...

  5. POJ 3318 Matrix Multiplication(矩阵乘法)

    题目链接 题意 : 给你三个n维矩阵,让你判断A*B是否等于C. 思路 :优化将二维转化成一维的.随机生成一个一维向量d,使得A*(B*d)=C*d,多次生成多次测试即可使错误概率大大减小. #inc ...

  6. poj 3318 Matrix Multiplication 随机化算法

    方法1:暴力法 矩阵乘法+优化可以卡时间过的. 方法2:随机化 随机构造向量x[1..n],则有xAB=xC;这样可以将小运算至O(n^2). 代码如下: #include<iostream&g ...

  7. POJ 3318 - Matrix Multiplication 第一次用随机化解决问题...

    随机化还是很厉害的...印象最深的是以前手写快排~~一般加个随机化会使耗时不受输入数据的..时间更加稳定 这个题是人品题了...开始交了好多遍都过不了..多交几次终于过了... Program: #i ...

  8. PKU 3318 Matrix Multiplication(随机化算法||状态压缩)

    题目大意:原题链接 给定三个n*n的矩阵A,B,C,验证A*B=C是否成立. 所有解法中因为只测试一组数据,因此没有使用memset清零 Hint中给的傻乎乎的TLE版本: #include<c ...

  9. PKU 3318 Matrix Multiplication(神奇的输入)

    #include<cstdio> using namespace std; ][]; ][],C[][]; int Read() { ; ; while((ch=getchar())==' ...

随机推荐

  1. LeetCode_Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...

  2. 极简AWR报告收集指导

    1.以oracle用户登录oracle数据库,执行如下命令登录数据库: sqlplus / as sysdba 2.运行如下命令: @?/rdbms/admin/awrrpt.sql 3.出现如下信息 ...

  3. Source insight添加工具自动排版

    当在网上找了一些别人的程序拿来学习,用Source insight来看时,会不会因为代码太乱看了义愤填膺呢? 有很多集成的开发环境可以自动排版,但source insight却不行!不过,有工具和配置 ...

  4. Hdu2425-Hiking Trip(优先队列搜索)

    Hiking in the mountains is seldom an easy task for most people, as it is extremely easy to get lost ...

  5. phpWeb

    Ruby on Rails框架在REST走得很前,开发时默认都按照RESTful风格搭建. <RESTful Web Services>是本好书 SOAP

  6. The Frog's Games(二分)

    The Frog's Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others) ...

  7. hdu4267 A Simple Problem with Integers

    A Simple Problem with Integers Time Limit: 5000/1500 MS (Java/Others) Memory Limit: 32768/32768 K (J ...

  8. MongoDB 数据库安装

    首先在官网上下载数据库:官网上提供了两种形式的数据库,一种是免安装版的,一种是安装版的.这点跟apache的tomcat类似,安装版的有可视化的界面对服务进行启动和关闭,可是还是比較喜欢免安装的.不解 ...

  9. linux在文件打包和压缩

    1. 打包和压缩文件 linux现在经常使用gzip和bzip2要压缩的文件.tar压缩文件. 经常使用的扩展: *.gz   gzip压缩文件 *.bz2  bzip2压缩的文件 *.tar   t ...

  10. 7. 稀疏表示之OMP,SOMP算法及openCV实现

    一.前言 稀疏表示是自上世纪90年代开始,从人眼的视觉感受野获得启示,逐渐被人们所研究.现在已经发展为一种重要的信息表示方法.所谓稀疏表示是指,一个信号在过完备字典中,可以由少数个原子线性表达, 其数 ...