题意 一个矩阵中 每一行 每一列 都可以倒置 在不断进行倒置后 求 左上的那个 N * N 矩阵 的和 最大为多少
思路 M = 2 * N 通过 倒置特性 我们可以发现,最左上的那个矩阵 第 [I][j] 位的那个数字 只能是通过第[M - 1 - i][j] 或者 [i][M - 1 - j] 或者 [M - 1 - i][M - 1 - j] 这三个位置上的数字 换过来的
所以 我们对于每个位置 只要遍历一下 相对应的 三个位置 取最大值 就可以了
AC代码
#include <cstdio> #include <cstring> #include <ctype.h> #include <cstdlib> #include <climits> #include <iostream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <map> #include <stack> #include <set> #include <numeric> #include <sstream> #include <iomanip> #include <limits> using namespace std; typedef long long ll; typedef long double ld; typedef pair <int, int> pii; typedef pair <ll, ll> pll; const double PI = 3.14159265358979323846264338327; const double E = exp(1); const double eps = 1e-6; const int INF = 0x3f3f3f3f; const int maxn = 256 + 5; const int MOD = 1e9 + 7; int a[maxn][maxn]; int main() { int t; cin >> t; while (t--) { int n; scanf("%d", &n); int m = 2 * n; for (int i = 0; i < m; i++) for (int j = 0; j < m; j++) scanf("%d", &a[i][j]); ll ans = 0; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { a[i][j] = max(a[i][m - 1 - j], a[i][j]); a[i][j] = max(a[m - 1 - i][j], a[i][j]); a[i][j] = max(a[m - 1 - i][m - 1 - j], a[i][j]); ans += a[i][j]; } } cout << ans << endl; } }转载于:https://www.cnblogs.com/Dup4/p/9433247.html
相关资源:workshop-html-css-flipping-cards-源码