poj 3318 Matrix Multiplication

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

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

 1 #include <cstdio>
2 #include <cstring>
3 #include <time.h>
4 #include <algorithm>
5 #define maxn 1010
6 using namespace std;
7
8 int a[maxn][maxn],b[maxn][maxn],c[maxn][maxn],d[maxn];
9 int n;
10 int b1[maxn],c1[maxn],a1[maxn];
11
12 int main()
13 {
14 while(scanf("%d",&n)!=EOF)
15 {
16 for(int i=0; i<n; i++)
17 {
18 for(int j=0; j<n; j++)
19 scanf("%d",&a[i][j]);
20 }
21 for(int i=0; i<n; i++)
22 {
23 for(int j=0; j<n; j++)
24 {
25 scanf("%d",&b[i][j]);
26 }
27 }
28 for(int i=0; i<n; i++)
29 {
30 for(int j=0; j<n; j++)
31 {
32 scanf("%d",&c[i][j]);
33 }
34 }
35 srand((unsigned int)time(0));
36 for(int i=0; i<n; i++)
37 {
38 d[i]=rand()%100;
39 }
40 for(int i=0; i<n; i++)
41 {
42 for(int j=0; j<n; j++)
43 {
44 b1[i]+=b[i][j]*d[j];
45 c1[i]+=c[i][j]*d[j];
46 }
47 }
48 for(int i=0; i<n; i++)
49 {
50 for(int j=0; j<n; j++)
51 {
52 a1[i]+=a[i][j]*b1[j];
53 }
54 }
55 bool flag=false;
56 for(int i=0; i<n; i++)
57 {
58 if(a1[i]!=c1[i])
59 {
60 flag=true;
61 break;
62 }
63 }
64 if(!flag) printf("YES\n");
65 else printf("NO\n");
66 }
67 return 0;
68 }

poj 3318 Matrix Multiplication,布布扣,bubuko.com

时间: 2024-10-09 08:55:50

poj 3318 Matrix Multiplication的相关文章

POJ 3318 Matrix Multiplication(随机化算法)

给你三个矩阵A,B,C.让你判断A*B是否等于C. 随机一组数据,然后判断乘以A,B之后是否与乘C之后相等. 很扯淡的啊,感觉这种算法不严谨啊... Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16255   Accepted: 3515 Description You are given three n × n matrices A, B and C. Does the e

POJ 3318 Matrix Multiplication(矩阵乘法)

题目链接 题意 : 给你三个n维矩阵,让你判断A*B是否等于C. 思路 :优化将二维转化成一维的.随机生成一个一维向量d,使得A*(B*d)=C*d,多次生成多次测试即可使错误概率大大减小. 1 //3318 2 #include <stdio.h> 3 #include <string.h> 4 #include <time.h> 5 #include <stdlib.h> 6 #include <iostream> 7 8 using nam

[ACM] POJ 3318 Matrix Multiplication (随机化算法)

Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 16118   Accepted: 3485 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 posit

POJ 题目3318 Matrix Multiplication(快速判断矩阵乘是否正确)

Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17132   Accepted: 3732 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 posit

POJ 3233 - Matrix Power Series ( 矩阵快速幂 + 二分)

POJ 3233 - Matrix Power Series ( 矩阵快速幂 + 二分) #include <cstdio> #include <cstring> #include <algorithm> using namespace std; typedef long long LL; #define MAX_SIZE 30 #define CLR( a, b ) memset( a, b, sizeof(a) ) int MOD = 0; int n, k; st

ACDream 1213 Matrix Multiplication (01矩阵处理)

Matrix Multiplication Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) Submit Statistic Next Problem Problem Description Let us consider undirected graph G = {V; E} which has N vertices and M edges. Incidence matrix of

Matrix multiplication

题目链接 题意: 给两个n*n的矩阵,求乘积后对3取摸的结果(1≤n≤800) 分析: 考虑一下为什么给3呢,对3取摸只可能得到0.1.2,都可以看作两位的,那么在乘法的时候我们可以用分配率将原来的矩阵乘法分成四个矩阵乘法,每个矩阵都只包括0和1.对于0/1矩阵的乘法,可以使用bitset来快速运算 const int MAXN = 801; bitset<MAXN> r1[MAXN], r2[MAXN], c1[MAXN], c2[MAXN]; int a[MAXN][MAXN]; int

HDU 4902 Matrix multiplication

点击打开链接 Matrix multiplication Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 2113    Accepted Submission(s): 956 Problem Description Given two matrices A and B of size n×n, find the product o

[求PN点] poj 2505 A multiplication game

题目链接: http://poj.org/problem?id=2505 A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5098   Accepted: 2573 Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers