• hdu Matrix Multiplication 写一个类似哈希函数的东西一切就解决了。


    Problem Description

    You are given three n × n matrices AB 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 AB and 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
    2 1 0 2 3 5 1 0 8 5 1 10 26
     
    Sample Output
    YES
    ***************************************************************************************************************************
     1 #include<iostream>
     2 #include<string>
     3 #include<cstring>
     4 #include<cstdio>
     5 #include<cmath>
     6 #include<queue>
     7 #include<algorithm>
     8 #include<vector>
     9 #define LL long long
    10 using namespace std;
    11 
    12 LL a[501][501],b[501][501],c[501][501];
    13 LL d[501],e[501],f[501],x[501];
    14 LL n,m,i,j,k;
    15 int main()
    16 {
    17     while(scanf("%lld",&n)!=EOF)
    18     {
    19         for(i=0; i<n; i++)
    20             for(j=0; j<n; j++)
    21                 scanf("%lld",&a[i][j]);
    22         for(i=0; i<n; i++)
    23             for(j=0; j<n; j++)
    24                 scanf("%lld",&b[i][j]);
    25         for(i=0; i<n; i++)
    26             for(j=0; j<n; j++)
    27                 scanf("%lld",&c[i][j]);
    28         for(i=0; i<n; i++)
    29             x[i]=i;
    30         for(i=0; i<n; i++)
    31             f[i]=e[i]=d[i]=0;
    32         for(i=0; i<n; i++)
    33             for(j=0; j<n; j++)
    34             {
    35                 e[i]+=b[i][j]*x[j];
    36                 f[i]+=c[i][j]*x[j];
    37             }
    38         for(i=0; i<n; i++)
    39             for(int j=0; j<n; j++)
    40                 d[i]+=a[i][j]*e[j];
    41         for(i=0; i<n; i++)
    42           if(d[i]!=f[i]) break;
    43         if(i<n)
    44             puts("NO");
    45         else
    46             puts("YES");
    47     }
    48     return 0;
    49 }
    View Code
  • 相关阅读:
    滑动窗口模板
    交换机命令
    针对织梦程序列表字段内可有可无的显示方法
    dedecms中常见问题修改方法
    redis系列之------字典
    1.InfluxDB-官方测试数据导入
    MYSQL第二课
    centos6.8下hadoop3.1.1完全分布式安装指南
    Mysql—添加用户并授权
    什么是全文检索
  • 原文地址:https://www.cnblogs.com/sdau--codeants/p/3521206.html
Copyright © 2020-2023  润新知