题意

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

在不断进行倒置后 求 左上的那个 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. C/C++ 内存管理总结

    C内存管理 存储时: 执行程序在存储时(没有调入到内存)分为代码区(text).数据区(data)和未初始化数据区(bss)3个部分. 1 代码区(text segment) 存放CPU执行的机器指令 ...

  2. docker 让容器执行命令 与 进入容器交互

    直接执行命令docker exec mynginx cat /etc/nginx/nginx.conf 进入容器交互docker exec -it 80nginx /bin/bash

  3. SSH框架整合时,如果某一个action提交请求时数据校验失败,后续请求全部失败

    © 版权声明:本文为博主原创文章,转载请注明出处 1.问题描述 SSH框架搭建好进行验证时发现,执行某个请求时,若参数校验失败,修改参数符合要求后再次请求依然失败.该请求一直报错如下: No resu ...

  4. 【已解决】ckfinder_php_3.4.4 IIS 报错 无效请求

    ckfinder_php_3.4.4 IIS 报错 无效请求 (Invalid request) Apache 正常,但是在IIS环境下报错,解决方法 设置 C:\Windows\Temp 目录 给 ...

  5. 企业级Nginx服务基础到架构优化详解

    1.隐藏nginx header版本号 2.更改源码隐藏软件名称 3.更改nginx默认用户及用户组 4.配置nginx worker进程个数 5.根据CPU核数进行nginx进程优化 6.nginx ...

  6. HTML5 2D平台游戏开发#9蓄力技

    在很多动作游戏中,玩家操控的角色可以施放出比普通攻击更强力的蓄力技,一般操作为按住攻击键一段时间然后松开,具体效果像下面这张图: 要实现这个操作首先要记录下按键被按住的时间,初始是0: this.sa ...

  7. Apache安全和强化的十三个技巧

    Apache是一个很受欢迎的web服务器软件,其安全性对于网站的安全运营可谓生死攸关.下面介绍一些可帮助管理员在Linux上配置Apache确保其安全的方法和技巧. 本文假设你知道这些基本知识: 文档 ...

  8. IIS 实现一个主机部署多个网站 共享80端口

    如果一个主机只是建立一个80端口的网站就有点浪费了,通过本文你就可以实现,在一个主机上建立多个80端口的站点,并通过不同的域名进行访问. 打开iis软件:控制面板-->管理工具-->Int ...

  9. Sql Server 查询一段日期内的全部礼拜天

    /* 查询一段日期内的全部礼拜天 @startdate 開始日期 @enddate 结束日期 */ declare @startDate datetime declare @endDate datet ...

  10. 小贝_php+redis简单实例

    php+redis简单实例 一.说明 因为redis是c/s架构.从这个角度上.不论什么符合redis的client要求的.都能够与redis进行通讯.官方提供了非常多的client. php在web ...