zoukankan      html  css  js  c++  java
  • 蓝桥杯矩阵乘法

    #include<iostream>


    using namespace std;


    void input(long long array[],long long length);
    void view(long long array[],long long length);
    void getValue(long long array[],long long temp[],long long length);
    long long getValue_temp(long long array[],long long temp[],long long length,long long row,long long colum);


    int main(int argc,char** argv){

    int M,N;
    cin >> M >> N;
    N = N - 1;

    long long data[M * M];
    long long temp[M * M];

    input(data,M);

    for(int i = 0;i < M * M;i++){

    temp[i] = data[i];
    }

    while(N){

    getValue(data,temp,M);
    N--;
    }

    view(data,M);

    return 0;
    }


    void input(long long array[],long long length){

    for(long long i = 0;i < length * length;i++){

    cin >> array[i];
    }
    }


    void view(long long array[],long long length){

    for(int i = 0;i < length * length;i++){

    cout << array[i] << " ";

    if((i + 1) % length == 0){

    cout << endl;
    }

    }
    }


    void getValue(long long array[],long long temp[],long long length){

    long long tt[length][length];
    long long order = 0;

    for(long long i = 0;i < length;i++){

    for(long long j = 0;j < length;j++){

    tt[i][j] = getValue_temp(array,temp,length,i,j);
    }
    }

    for(long long i = 0;i < length;i++){

    for(long long j = 0;j < length;j++){

    array[order] = tt[i][j];
    order++;
    }
    }
    }


    long long getValue_temp(long long array[],long long temp[],long long length,long long row,long long colum){

    long long at[length][length];
    long long tt[length][length];
    long long sum = 0;

    int order = 0;
    for(long long i = 0;i < length;i++){

    for(long long j = 0;j < length;j++){

    at[i][j] = array[order];
    order++;
    }
    }
    order = 0;
    for(long long i = 0;i < length;i++){

    for(long long j = 0;j < length;j++){

    tt[i][j] = temp[order];
    order++;
    }
    }

    for(long long i = 0;i < length;i++){

    sum = sum + at[row][i] * tt[i][colum];
    }

    return sum;
    }

  • 相关阅读:
    Lab EIGRP不等价负载均衡
    Lab EIGRP metric计算
    EIGRP Troubleshooting Summary
    EIGRP Query Range查询过程详细分析
    EIGRP Auto-Summary Affect The Query Range
    EIGRP Distribute-list Affect The Query Range
    Understanding EIGRP Queries
    EIGRP DUAL
    33、为什么析构函数一般写成虚函数
    32、C和C++的类型安全
  • 原文地址:https://www.cnblogs.com/viplanyue/p/12700714.html
Copyright © 2011-2022 走看看