zoukankan      html  css  js  c++  java
  • 矩阵相乘

    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <stdlib.h>
    #include <iostream>
    #include <sstream>
    #include <algorithm>
    #include <string>
    #include <queue>
    #include <map>
    #include <vector>
    using namespace std;
    const int maxn = 1e4+10;
    const int maxm = 1e4+10;
    const int inf = 0x3f3f3f3f;
    const int mod = 998244353;
    const double epx = 1e-10;
    typedef long long ll;
    const ll INF = 1e18;
    int a[maxn][maxn];
    int b[maxn][maxn];
    int c[maxn][maxn];
    int main()
    {
        int n,m,n1,m1;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=m;j++)
                cin>>a[i][j];
        }
        cin>>n1>>m1;
        for(int i=1;i<=n1;i++)
        {
            for(int j=1;j<=m1;j++)
                cin>>b[i][j];
        }
        if(m!=n1)
            cout<<"Error: "<<m<<" != "<<n1<<endl;
        else
        {
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<=m1;j++)
                {
                    int sum=0;
                    for(int k=1;k<=m;k++)
                    {
                        sum+=a[i][k]*b[k][j];
                    }
                    c[i][j]=sum;
                }
            }
            cout<<n<<" "<<m1<<endl;
            for(int i=1;i<=n;i++)
            {
                for(int j=1;j<m1;j++)
                {
                    cout<<c[i][j]<<" ";
                }
                cout<<c[i][m1]<<endl;
            }
        }
    }
  • 相关阅读:
    less中遇到的一些特殊的写法
    观察者模式
    发布订阅模式
    javascript中的函数
    关于js中this的理解和作用
    [Oracle]Oracle镜像安装及使用教程
    log4net日志配置
    过滤器
    .net core 处理 中文乱码
    Fromform
  • 原文地址:https://www.cnblogs.com/stranger-/p/8540623.html
Copyright © 2011-2022 走看看