zoukankan      html  css  js  c++  java
  • 51NOD 1137 矩阵乘法

    1137 矩阵乘法

    基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
    收藏
    关注
    给出2个N * N的矩阵M1和M2,输出2个矩阵相乘后的结果。
    Input
    第1行:1个数N,表示矩阵的大小(2 <= N <= 100)
    第2 - N + 1行,每行N个数,对应M1的1行(0 <= M1[i] <= 1000)
    第N + 2 - 2N + 1行,每行N个数,对应M2的1行(0 <= M2[i] <= 1000)
    Output
    输出共N行,每行N个数,对应M1 * M2的结果的一行。
    Input示例
    2
    1 0
    0 1
    0 1
    1 0
    Output示例
    0 1
    1 0

    #include <iostream>
    #include <algorithm>
    
    using namespace std ; 
    
    #define maxn 200
    int node1[maxn][maxn] ; 
    int node2[maxn][maxn] ; 
    int result[maxn][maxn]; 
    int main(){
        int n ; 
        
        while(cin >> n ){
            for(int i = 0 ; i < n ; i ++){
                for(int j = 0 ; j < n ; j ++){
                    cin >> node1[i][j] ; 
                }
            }
            for(int i = 0 ; i < n ; i ++){
                for(int j = 0 ; j < n ; j ++){
                    cin >> node2[i][j] ; 
                }
            }
            
            for(int i = 0 ; i < n ; i ++ ) {
                for(int j = 0 ; j < n ; j ++){
                    result[i][j] = 0 ; 
                    for(int k = 0 ; k < n ; k++){
                        result[i][j] += node1[i][k] * node2[k][j] ;  
                    }
                }
            }
            
            for(int i = 0 ; i < n ; i ++){
                for(int j = 0 ; j < n ; j ++ ){
                    if(j == 0 )
                        cout << result[i][j]  ; 
                    else {
                        cout << " " << result[i][j]  ; 
                    }
                }
                cout << endl ; 
            }
        }    
        
        return 0 ; 
    }
  • 相关阅读:
    线程的中断.interrupt
    线程的加入.join()
    Runnable接口
    线程Thread类
    求和、均值
    最值、对应索引位置
    数组、冒泡排序
    获取Methods成员方法类
    获取Field成员变量类
    基于WinDbg的内存泄漏分析
  • 原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9289039.html
Copyright © 2011-2022 走看看