poj 3318

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36651153/article/details/81477443

代码如下

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<time.h>
using namespace std;
const int maxn=505;
int A[maxn][maxn],B[maxn][maxn],C[maxn][maxn];
int n;
bool Solve()
{
    int cnt=50000;
    while(cnt--) {
        int r=rand()%n;
        int c=rand()%n;
        int temp=0;
        for(int i=0;i<n;i++) {
            temp+=A[r][i]*B[i][c];
        }
        if(temp!=C[r][c]) {
            return false;
        }
    }
    return true;
}
int main()
{
    scanf("%d",&n);
        srand(time(NULL));
        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]);
            }
        }
        if(Solve()) {
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }

}

猜你喜欢

转载自blog.csdn.net/qq_36651153/article/details/81477443
今日推荐