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. RMAN学习笔记

    RMAN:如果RMAN连接一个远程数据库,格式:RMAN>rman target sys/jxsrpv@test 1.列出备份信息,所有的备份信息 RMAN>list backup of ...

  2. Win8 X64下JDK版本切换问题

    1:现在笔记本上安装的是,执行java -version: 2:现在又安装了,想通过修改环境变量,使JDK切换到1.6版本上 JDK的安装目录:D:\Java\ 修改环境变量: (1)JAVA_HOM ...

  3. LeetCode_Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  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. Hive 8、Hive2 beeline 和 Hive jdbc

    1.Hive2 beeline  Beeline 要与HiveServer2配合使用,支持嵌入模式和远程模式 启动beeline 打开两个Shell窗口,一个启动Hive2 一个beeline连接hi ...

  6. sleep()函数的的意义

    ===============WINDOWS平台下:====================== 关于VOID Sleep(DWORD dwMilliseconds);函数,许多人都觉得,它是告诉系统 ...

  7. SoupUI接口测试学习分享

    一.SoapUI的使用 我们主要用SoapUI的REST 测试功能来测试我们协议接口.RESTful是一种服务端API的规范,每个资源对应唯一的URI,然后用HTTP的POST.GET.PUT.DEL ...

  8. Impala与Hive的比較

    1. Impala架构        Impala是Cloudera在受到Google的Dremel启示下开发的实时交互SQL大数据查询工具,Impala没有再使用缓慢的Hive+MapReduce批 ...

  9. 成语接龙(dfs)

    成语接龙 Time Limit: 1000 MS Memory Limit: 32768 K Total Submit: 92(17 users) Total Accepted: 23(14 user ...

  10. Flexbox属性可视化指南

    Flexbox 布局(国内很多人称为弹性布局)正式的全称为 CSS Flexible Box布局模块,它是CSS3新增的一种布局模式.它可以很方便地用来改善动态或未知大小的元素的对齐,方向和顺序等等. ...