https://codeforces.com/gym/101341/problem/I
题意:
给定三个矩阵ABC,问A*b是否等于c
代码:
1 #include <stdio.h> 2 #include <string.h> 3 #include <stdlib.h> 4 5 long long mod = 1e9+7; 6 7 long long a[1005][1005], b[1005][1005], c[1005][1005]; 8 long long re1[1005], re2[1005], re3[1005]; 9 long long ran[1005]; 10 11 int main() 12 { 13 long long n, i, j; 14 scanf("%lld", &n); 15 for(i=0;i<n;i++) 16 { 17 for(j=0;j<n;j++) 18 { 19 scanf("%lld", &a[i][j]); 20 } 21 } 22 for(i=0;i<n;i++) 23 { 24 for(j=0;j<n;j++) 25 { 26 scanf("%lld", &b[i][j]); 27 } 28 } 29 30 for(i=0;i<n;i++) 31 { 32 for(j=0;j<n;j++) 33 { 34 scanf("%lld", &c[i][j]); 35 } 36 } 37 for(i=0;i<n;i++) 38 { 39 ran[i] = rand() % 100 + 1; 40 } 41 //cheng 1 1 1 1 1 42 for(j=0;j<n;j++) 43 { 44 re1[j] = 0; 45 for(i=0;i<n;i++) 46 { 47 re1[j] = (re1[j] + ran[i] * a[i][j]) % mod; 48 } 49 } 50 51 for(j=0;j<n;j++) 52 { 53 re2[j] = 0; 54 for(i=0;i<n;i++) 55 { 56 re2[j] = (re2[j] + re1[i] * b[i][j]) % mod; 57 } 58 } 59 60 for(j=0;j<n;j++) 61 { 62 re3[j] = 0; 63 for(i=0;i<n;i++) 64 { 65 re3[j] = (re3[j] + ran[i] * c[i][j]) % mod; 66 } 67 } 68 69 for(i=0;i<n;i++) 70 { 71 if(re2[i]!=re3[i]) break; 72 } 73 if(i<n) printf("NO\n"); 74 else printf("YES\n"); 75 return 0; 76 }