题意

一个矩阵中 每一行 每一列 都可以倒置

在不断进行倒置后 求 左上的那个 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;
}
}

HackerRank - flipping-the-matrix 【数学】的更多相关文章

  1. Looksery Cup 2015 H. Degenerate Matrix 数学

    H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...

  2. ACM学习历程—HDU5490 Simple Matrix (数学 && 逆元 && 快速幂) (2015合肥网赛07)

    Problem Description As we know, sequence in the form of an=a1+(n−1)d is called arithmetic progressio ...

  3. [C2P1] Andrew Ng - Machine Learning

    About this Course Machine learning is the science of getting computers to act without being explicit ...

  4. 861. Score After Flipping Matrix

    We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...

  5. LC 861. Score After Flipping Matrix

    We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...

  6. 数学-Matrix Tree定理证明

    老久没更了,冬令营也延期了(延期后岂不是志愿者得上学了?) 最近把之前欠了好久的债,诸如FFT和Matrix-Tree等的搞清楚了(啊我承认之前只会用,没有理解证明--),FFT老多人写,而Matri ...

  7. 【数学】Matrix Multiplication

                                 Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total S ...

  8. 数学(矩阵乘法,随机化算法):POJ 3318 Matrix Multiplication

    Matrix Multiplication Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17783   Accepted: ...

  9. 【考虑周全+数学变形】【11月赛】Is it a fantastic matrix?

    Is it a fantastic matrix? Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/ ...

  10. [LeetCode] Score After Flipping Matrix 翻转矩阵后的分数

    We have a two dimensional matrix A where each value is 0 or 1. A move consists of choosing any row o ...

随机推荐

  1. [转]Tomcat工作原理详解

    一.Tomcat背景 自从JSP发布之后,推出了各式各样的JSP引擎.Apache Group在完成GNUJSP1.0的开发以后,开始考虑在SUN的JSWDK基础上开发一个可以直接提供Web服务的JS ...

  2. JS常用正则表达式大全

    转载自:http://blog.csdn.net/lun379292733/article/details/8169807/ <script type="text/JavaScript ...

  3. [[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"] 找不到对应的文件解决方法

    最近在使用[[NSBundle mainBundle] pathForResource:@"name" ofType:@"type"]时,找不到其对应的文件,文 ...

  4. jira报错,此域不支持您输入的日期

    jira报错,此域不支持您输入的日期 解决方法: 使用20117-1-1这样的格式输入,不要用选择日期.具体原因未知.

  5. Godaddy域名 绑定ip 服务器

    比如我的域名是wmxl.info 第一个红框代表wmxl.info 绑定的 211.83.110.216 第一个代表www.wmxl.info 绑定的 211.83.110.216, 你也可以换一个服 ...

  6. java.String中的方法

    (String) str.trim() 该方法返回一个复制该字符串的开头和结尾的白色空格去掉,或字符串,如果它没有头或尾空白. (Boolean) str.contains(str1) 判断 str ...

  7. iOS tableView高度缓存

    tableView计算完高度后,把高度缓存起来,避免下次重复计算,以减少不必要的消耗 // declare cellHeightsDictionary NSMutableDictionary *cel ...

  8. centos 防火墙开放80端口

    辛辛苦苦编译安装完Ngnix,mysql ,PHP,后发现不能访问,后来发现是防火墙把80端口给禁用了.开启之:(以下参考自:http://llhdf.javaeye.com/blog/526176) ...

  9. Android发短信

    设置应用一打开时候的背景图片 去掉相对布局时候的标题 去除标题必须在setContentView(R.layout.activity_main)之前. @Override protected void ...

  10. android开发中遇到的问题汇总【九】

    244.http请求的url含有中字符时.须要Uri编码.Uri.encoder() 245.使用androidstudio时,不知道什么原因svn不见了 Android Studio missing ...