Skip to content

Commit

Permalink
AcWing 3535. C翻转
Browse files Browse the repository at this point in the history
Signed-off-by: Tategoto Azarasi <2724167997@qq.com>
  • Loading branch information
tategotoazarasi committed Aug 9, 2024
1 parent a22fc1a commit 6e82d17
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 18 deletions.
63 changes: 48 additions & 15 deletions acwing408.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,21 +1508,6 @@ namespace acwing {
int main(istream &cin, ostream &cout) {
int n, p;
cin >> n >> p;
/*Matrix mat = Matrix(n);
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cin >> mat[i][j];
}
}
for(int i = 1; i < p; i++) {
mat = mat * mat;
}
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
cout << mat[i][j] << ' ';
}
cout << endl;
}*/
vector<Matrix *> mats = vector<Matrix *>(p + 1, nullptr);
mats[1] = new Matrix(n);
for(int i = 0; i < n; i++) {
Expand Down Expand Up @@ -1560,4 +1545,52 @@ namespace acwing {
return res;
}
}// namespace acwing3534

/**
* @brief 3535. C翻转
*/
namespace acwing3535 {
int main(istream &cin, ostream &cout) {
int dir, len, x, y;

vector<vector<int>> mat = vector<vector<int>>(6, vector<int>(6, 0));
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= 5; j++) {
cin >> mat[i][j];
}
}
vector<vector<int>> ret = mat;
cin >> dir >> len >> x >> y;
int transform[2][2][2] = {
{{0, 1},
{-1, 0}},
{{0, -1},
{1, 0}},
};
dir--;
for(int i = x; i < x + len; i++) {
for(int j = y; j < y + len; j++) {
int i0 = i - x + 1;
int j0 = j - y + 1;
int i2 = transform[dir][0][0] * i0 + transform[dir][0][1] * j0;
int j2 = transform[dir][1][0] * i0 + transform[dir][1][1] * j0;
if(dir == 0) {
j2 += len + 1;
} else {
i2 += len + 1;
}
i2 += x - 1;
j2 += y - 1;
ret[i2][j2] = mat[i][j];
}
}
for(int i = 1; i <= 5; i++) {
for(int j = 1; j <= 5; j++) {
cout << ret[i][j] << ' ';
}
cout << endl;
}
return 0;
}
}// namespace acwing3535
}// namespace acwing
9 changes: 8 additions & 1 deletion acwing408.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,19 @@ namespace acwing {
}

/**
* 3534. 矩阵幂
* @brief 3534. 矩阵幂
*/
namespace acwing3534 {
Matrix getMat(vector<Matrix *> &mat, int p);
int main(istream & /*cin*/, ostream & /*cout*/);
}// namespace acwing3534

/**
* @brief 3535. C翻转
*/
namespace acwing3535 {
int main(istream & /*cin*/, ostream & /*cout*/);
}
}// namespace acwing

#endif//PROBLEMSCPP_ACWING408_H
45 changes: 43 additions & 2 deletions acwing408_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1789,8 +1789,8 @@ namespace acwing {
}// namespace acwing3527

/**
* 3534. 矩阵幂
*/
* @brief 3534. 矩阵幂
*/
namespace acwing3534 {
TEST(acwing3534, case1) {
istringstream in("2 2\n"
Expand All @@ -1804,4 +1804,45 @@ namespace acwing {
ans);
}
}// namespace acwing3534

/**
* @brief 3535. C翻转
*/
namespace acwing3535 {
TEST(acwing3535, case1) {
istringstream in("1 2 3 4 5\n"
"6 7 8 9 10\n"
"11 12 13 14 15\n"
"16 17 18 19 20\n"
"21 22 23 24 25\n"
"1 3 1 1");
auto out = ostringstream();
main(in, out);
const auto ans = out.str();
ASSERT_EQ("11 6 1 4 5 \n"
"12 7 2 9 10 \n"
"13 8 3 14 15 \n"
"16 17 18 19 20 \n"
"21 22 23 24 25 \n",
ans);
}

TEST(acwing3535, case2) {
istringstream in("19 5 7 16 12\n"
"17 9 6 9 11\n"
"9 19 14 10 8\n"
"11 12 20 2 13\n"
"16 10 7 2 10\n"
"1 2 3 4");
auto out = ostringstream();
main(in, out);
const auto ans = out.str();
ASSERT_EQ("19 5 7 16 12 \n"
"17 9 6 9 11 \n"
"9 19 14 2 10 \n"
"11 12 20 13 8 \n"
"16 10 7 2 10 \n",
ans);
}
}// namespace acwing3535
}// namespace acwing

0 comments on commit 6e82d17

Please sign in to comment.