POJ 3318 Matrix Multiplication(随机化算法)
来源:互联网 发布:钢琴知乎 编辑:程序博客网 时间:2024/06/10 09:17
给你三个矩阵A,B,C。让你判断A*B是否等于C。
随机一组数据,然后判断乘以A,B之后是否与乘C之后相等。
很扯淡的啊,感觉这种算法不严谨啊、、、
Matrix Multiplication
Time Limit: 2000MS Memory Limit: 65536KTotal Submissions: 16255 Accepted: 3515
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
21 02 35 10 85 110 26
Sample Output
YES
Hint
Multiple inputs will be tested. So O(n3) algorithm will get TLE.
#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <time.h>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )#define Mod 1000000007#define LL long longusing namespace std;const int maxn = 510;int a[maxn][maxn];int b[maxn][maxn];int c[maxn][maxn];int f[maxn];int aa[maxn];int bb[maxn];int cc[maxn];int main(){ int n; cin >>n; memset(aa, 0, sizeof(aa)); memset(bb, 0, sizeof(bb)); memset(cc, 0, sizeof(cc)); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d",&a[i][j]); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d",&b[i][j]); for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) scanf("%d",&c[i][j]); srand((unsigned int)time(0)); for(int i = 0; i < n; i++) f[i] = rand()%100; for(int i = 0; i < n; i++) { for(int j = 0; j < n; j++) { bb[i] += b[i][j]*f[j]; cc[i] += c[i][j]*f[j]; } } for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) aa[i] += a[i][j]*bb[j]; int flag = 0; for(int i = 0; i < n; i++) { if(aa[i] != cc[i]) { flag = 1; break; } } if(flag) cout<<"NO"<<endl; else cout<<"YES"<<endl;}
0 0
- POJ 3318 Matrix Multiplication(随机化算法)
- POJ 3318 Matrix Multiplication 随机化算法
- 【POJ-3318-Matrix Multiplication 随机化算法】
- [ACM] POJ 3318 Matrix Multiplication (随机化算法)
- POJ 3338 Matrix Multiplication(随机化算法)
- poj 3318 Matrix Multiplication(随机化)
- POJ 3318 - Matrix Multiplication 第一次用随机化解决问题...
- POJ 3318 Matrix Multiplication 解题报告 (随机化 & 矩阵性质)
- POJ 3318 Matrix Multiplication【矩阵相乘——随机化检测】
- POJ 3318 Matrix Multiplication(随机算法)
- POJ 3318 Matrix Multiplication
- Poj 3318 Matrix Multiplication
- POJ 3318 Matrix Multiplication
- poj_3318 Matrix Multiplication(随机化算法+压缩矩阵)
- poj3318——Matrix Multiplication(随机化算法)
- 【POJ 3318】Matrix Multiplication(随机<RP>……算法?)
- POJ---3318-Matrix Multiplication 水
- POJ 3318 Matrix Multiplication 随机
- msf 小记
- ubuntu下Android4.4源码导入eclipse
- GRE工作原理
- 算法竞赛入门经典-第五章源代码
- C++设计模式之单例模式
- POJ 3318 Matrix Multiplication(随机化算法)
- 知识点:各种容器介绍(示例为TreeSet),TreeSet的遍历
- Exponentiation(高精度)
- uva 12563 - Jin Ge Jin Qu hao
- mysql的数据类型
- PHP的POST处理方法汇总
- xen.cfg的写法及附带的一个例子
- poj 3692 Kindergarten 二分匹配
- Codeforces 417D