题意

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

在不断进行倒置后 求 左上的那个 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. 【BIEE】10_资料库查看数据报错

    导入元数据后,在资料库右键物理表名,[查看数据]报错: 出现这个问题,没搞明白是为啥- 后来百度意外发现一个方法,修改NQSConfig.INI文件即可解决问题 那么就开始来搞定这个问题 [1]打开路 ...

  2. 正则表达式Pattern ,Matcher

    正则表达式:符合一定规则的表达式 作用:用于专门操作字符串 特点:用于一些特定的符号来表示一些代码的操作,这样就简化代码的书写 学习正则表达式就是要学习一些特殊符号的使用 好处:简化对字符串复杂的操作 ...

  3. 【hadoop之翊】——windows 7使用eclipse下hadoop应用开发环境搭建

    由于一些缘故,这节内容到如今才写.事实上弄hadoop有一段时间了,能够编写一些小程序了,今天来还是来说说环境的搭建.... 说明一下:这篇文章的步骤是接上一篇的hadoop文章的:http://bl ...

  4. MySQL四-2:完整性约束

    阅读目录 一 介绍 二 not null与default 三 unique 四 primary key 五 auto_increment 六 foreign key 七 作业 一 介绍 约束条件与数据 ...

  5. C指针解析 ------ 指针的算术运算

    本文是自己学习所做笔记.欢迎转载.但请注明出处:http://blog.csdn.net/jesson20121020 指针是一个特殊的变量,表示一个地址,而地址能够上减去或加上一个整数,从而能够表示 ...

  6. dedecms增加自定义表单管理员

    打开\dede\inc\grouplist.txt 添加 >>自定义表单 >f_List>列出表单 >f_New>新建表单 >f_Edit>编辑表单 & ...

  7. Hibernate 中的DetachedCriteria。

    今天看到项目中在Web层使用DetachedCriteria进行多条件查询操作,如果在web层做持久层操作,事物还存在吗?这是我第一反应,于是乎就去网上查资料了.结果发现即在web层,程序员使用Det ...

  8. linux 时间与本地时间不对应解决办法

    date -s '2015-01-22 13:00:22' #设置时间 clock -w #写入mac操作系统中 -------------------------------------date - ...

  9. PMD:Java源代码扫描器

    PMD是一个开源代码分析器.可以查找常见编程缺陷,比如未使用的变量.空catch代码块.不必要的对象创建等.支持Java.JavaScript.PLSQL.Apache Velocity.XML.XS ...

  10. cnn 实例

    http://www.geekcome.com/content-10-3761-1.html http://www.geekcome.com/content-10-3761-1.html http:/ ...