problemscpp
A collection of my answers to algorithm problems in c++.
函数
acwing::acwing3534 命名空间参考

  1. 矩阵幂
更多...

函数

Matrix getMat (vector< Matrix * > &mat, int p)
 
int main (istream &cin, ostream &cout)
 
 TEST (acwing3534, case1)
 

详细描述

  1. 矩阵幂
  1. 矩阵幂

函数说明

◆ getMat()

Matrix acwing::acwing3534::getMat ( vector< Matrix * > &  mat,
int  p 
)

在文件 acwing408.cpp1529 行定义.

1529 {
1530 if(mat[p] != nullptr) {
1531 return *mat[p];
1532 }
1533 Matrix res = Matrix::identity((*mat[1])[1].size());
1534 for(int i = 0; p >> i != 0; i++) {
1535 int masked = p & (1 << i);
1536 if(masked != 0) {
1537 if(masked != p) {
1538 res = res * getMat(mat, p & (1 << i));
1539 } else {
1540 Matrix m2 = getMat(mat, masked >> 1);
1541 res = res * m2 * m2;
1542 }
1543 }
1544 }
1545 mat[p] = new Matrix(res);
1546 return res;
1547 }
Matrix getMat(vector< Matrix * > &mat, int p)
Definition: acwing408.cpp:1529
矩阵
Definition: templates.h:107
static Matrix identity(int n)
Definition: templates.cpp:557

引用了 getMat() , 以及 Matrix::identity().

被这些函数引用 getMat() , 以及 main().

◆ main()

int acwing::acwing3534::main ( istream &  cin,
ostream &  cout 
)

在文件 acwing408.cpp1509 行定义.

1509 {
1510 int n, p;
1511 cin >> n >> p;
1512 vector<Matrix *> mats = vector<Matrix *>(p + 1, nullptr);
1513 mats[1] = new Matrix(n);
1514 for(int i = 0; i < n; i++) {
1515 for(int j = 0; j < n; j++) {
1516 cin >> (*mats[1])[i][j];
1517 }
1518 }
1519 Matrix mat = getMat(mats, p);
1520 for(int i = 0; i < n; i++) {
1521 for(int j = 0; j < n; j++) {
1522 cout << mat[i][j] << ' ';
1523 }
1524 cout << endl;
1525 }
1526 return 0;
1527 }

引用了 getMat().

被这些函数引用 TEST().

◆ TEST()

acwing::acwing3534::TEST ( acwing3534  ,
case1   
)

在文件 acwing408_test.cpp1795 行定义.

1795 {
1796 istringstream in("2 2\n"
1797 "9 8\n"
1798 "9 3");
1799 auto out = ostringstream();
1800 main(in, out);
1801 const auto ans = out.str();
1802 ASSERT_EQ("153 96 \n"
1803 "108 81 \n",
1804 ans);
1805 }
int main(int argc, char **argv)
Definition: main.cpp:5

引用了 main().