标签:之间 思路 == 乘法 mes int cto win 直接
1 #include<iostream> 2 #include<windows.h> 3 #include<vector> 4 5 using namespace std; 6 7 int main() 8 { 9 int n,c; 10 11 cin >> n >> c; 12 vector< vector<int> > a(n, vector<int>(n, 0)); 13 vector< vector<int> > b(n, vector<int>(n, 0)); 14 vector< vector<int> > d(n, vector<int>(n, 0)); 15 if(c == 0) 16 { 17 for(int i = 0; i < n; i++) 18 { 19 for(int j = 0; j < n; j++) 20 { 21 if(i == j) 22 { 23 cout << "1" << " "; 24 } 25 else 26 { 27 cout << a[i][j] << " "; 28 } 29 30 } 31 cout << endl; 32 } 33 return 0; 34 } 35 36 for(int i = 0; i < n; i++) //生成矩阵 37 { 38 for(int j = 0; j < n; j++) 39 { 40 cin >> a[i][j]; 41 } 42 } 43 b = a; //c++优势!! 44 if(c == 1) 45 { 46 for(int i = 0; i < n; i++) 47 { 48 for(int j = 0; j < n; j++) 49 { 50 cout << b[i][j] << " "; 51 } 52 cout << endl; 53 } 54 return 0; 55 } 56 57 for(int i = 2; i <= c; i++) //最外层循环控制幂 58 { 59 for(int j = 0; j < n; j++) 60 { 61 for(int k = 0; k < n; k++) 62 { 63 int sum = 0; 64 for(int l = 0; l < n; l++) 65 { 66 sum += a[j][l]*b[l][k]; 67 } 68 d[j][k] = sum; 69 } 70 } 71 b = d; 72 } 73 74 for(int i = 0; i < n; i++) 75 { 76 for(int j = 0; j < n; j++) 77 { 78 cout << d[i][j] << " "; 79 } 80 cout << endl; 81 } 82 83 system("pause"); 84 return 0; 85 }
标签:之间 思路 == 乘法 mes int cto win 直接
原文地址:https://www.cnblogs.com/ZhengLijie/p/12755285.html