poj3318 Matrix Multiplication

题意:给定$n*n(n<=500)$的矩阵$A,B,C$,如果$A*B==C$,输出“YES”,否则为“NO”;多组数据,$O(n^{3})$必T

我们可以随机生成一个神奇的列向量$v$,你可以把它看做n*1或1*n的矩阵,里面的元素随机为0或1

蓝后我们考察 $A*(B*v)$和$C*v$是否相等

灰常显然 $A*B!=C  ==>  A*(B*v)!=C*v$

那么我们每次判断有$\frac{1}{2}$的概率判错

于是我们多判几次

试60次时,判错率$=2^{-60}\approx10^{-20}$

end.

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#define re register
using namespace std;
template<typename T>T max(T &a,T &b){return a>b?a:b;}
template<typename T>T min(T &a,T &b){return a<b?a:b;}
#define N 501
int n,k,u,a[N][N],b[N][N],c[N][N],d[N],e[N],f[N];
int main(){
srand();
while(scanf("%d",&n)!=EOF){
for(re int i=;i<=n;++i)
for(re int j=;j<=n;++j)
scanf("%d",&a[i][j]);
for(re int i=;i<=n;++i)
for(re int j=;j<=n;++j)
scanf("%d",&b[i][j]);
for(re int i=;i<=n;++i)
for(re int j=;j<=n;++j)
scanf("%d",&c[i][j]);
for(k=;k<=;++k){
for(re int i=;i<=n;++i) d[i]=rand()&;
for(re int i=;i<=n;++i){
e[i]=;
for(re int j=;j<=n;++j)
e[i]+=c[i][j]*d[j];
}
for(re int i=;i<=n;++i){
f[i]=;
for(re int j=;j<=n;++j)
f[i]+=b[i][j]*d[j];
}
for(re int i=;i<=n;++i) d[i]=f[i];
for(re int i=;i<=n;++i){
f[i]=;
for(re int j=;j<=n;++j)
f[i]+=a[i][j]*d[j];
}
for(u=;u<=n&&e[u]==f[u];++u);
if(u<=n) break;
}puts(k>?"YES\n":"NO\n");
}return ;
}

poj3318 Matrix Multiplication的更多相关文章

  1. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  2. hdu 4920 Matrix multiplication bitset优化常数

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  3. 矩阵乘法 --- hdu 4920 : Matrix multiplication

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  4. hdu4920 Matrix multiplication 模3矩阵乘法

    hdu4920 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 ...

  5. acdeream Matrix Multiplication

    D - Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/O ...

  6. HDU 4920 Matrix multiplication 矩阵相乘。稀疏矩阵

    Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/ ...

  7. Matrix multiplication hdu4920

    Problem Description Given two matrices A and B of size n×n, find the product of them. bobo hates big ...

  8. HDU-4920 Matrix multiplication

    矩阵相乘,采用一行的去访问,比采用一列访问时间更短,根据数组是一行去储存的.神奇小代码. Matrix multiplication Time Limit: 4000/2000 MS (Java/Ot ...

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

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

随机推荐

  1. x86 x64下调用约定浅析

    x86平台下调用约定 我们都知道x86平台下常用的有三种调用约定,__cdecl.__stdcall.__fastcall.我们分别对这三种调用约定进行分析. __cdecl __cdecl是C/C+ ...

  2. LeetCode——Palindrome Linked List

    Description: Given a singly linked list, determine if it is a palindrome. Follow up:Could you do it ...

  3. Android反编译技术总结

    一.Apk反编译工具及其使用方法 1.原理 学习反编译之前,建议先学习一下Apk打包的过程,明白打包完成后的Apk里面都有什么文件,各种文件都是怎么生成的. 这里有两篇AndroidWeekly中推荐 ...

  4. Tomcat远程任意代码执行漏洞及其POC(CVE-2017-12617)

    一.原理分析: 只需参数readonly设置为false或者使用参数readonly设置启用WebDAV servlet false,则Tomcat可以不经任何身份验证的控制直接接收PUT方式上传的文 ...

  5. oracle的connect by level的示例

    SELECT regexp_substr('CITY_AA,CITY_BB,CITY_CC,CITY_DD', '[^,]+', 1, LEVEL) t FROM dualCONNECT BY reg ...

  6. shell用curl抓取页面乱码,参考一下2方面(转)

    1.是用curl抓取的数据是用类似gzip压缩后的数据导致的乱码.乱码:curl www.1ting.com |more乱码:curl -H "Accept-Encoding: gzip&q ...

  7. angularJs初体验,实现双向数据绑定!使用体会:比较爽

    使用初体验:ng 双向数据绑定: 最简单的双向数据绑定:(使用默认模块控制) <body ng-app> <input type="text" ng-model= ...

  8. Think PHP递归获取所有的子分类的ID (删除当前及子分类)

    递归获取所有的子分类的ID: //递归获取所有的子分类的ID function get_all_child($array,$id){ $arr = array(); foreach($array as ...

  9. MyBatis DAO层传递参数到mapping.xml 几种方式

    Dao层传递参数到mapping.xml文件的几种方式:(Mybatis传值总结) 第一种:传递单个参数 Dao层Code片段: /** * 根据articleId查询XXXX详情. * * @par ...

  10. postgresql----继承表INHERITS PARENT TABLE

    使用INHERITS创建的新表会继承一个或多个父表,子表只会继承父表的表结构和NOT NULL,DEFAULT,CHECK三种约束,主键,外键和唯一键以及索引不会被继承,所以修改父表的结构(增删字段) ...