HackerRank - flipping-the-matrix 【数学】
题意
一个矩阵中 每一行 每一列 都可以倒置
在不断进行倒置后 求 左上的那个 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 【数学】的更多相关文章
- Looksery Cup 2015 H. Degenerate Matrix 数学
H. Degenerate Matrix Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/549/ ...
- 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 ...
- [C2P1] Andrew Ng - Machine Learning
About this Course Machine learning is the science of getting computers to act without being explicit ...
- 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 ...
- 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 ...
- 数学-Matrix Tree定理证明
老久没更了,冬令营也延期了(延期后岂不是志愿者得上学了?) 最近把之前欠了好久的债,诸如FFT和Matrix-Tree等的搞清楚了(啊我承认之前只会用,没有理解证明--),FFT老多人写,而Matri ...
- 【数学】Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total S ...
- 数学(矩阵乘法,随机化算法):POJ 3318 Matrix Multiplication
Matrix Multiplication Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 17783 Accepted: ...
- 【考虑周全+数学变形】【11月赛】Is it a fantastic matrix?
Is it a fantastic matrix? Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/ ...
- [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 ...
随机推荐
- eclipse debug调试java程序的九个技巧
九个技巧: 逻辑结构 条件debug 异常断点 单步过滤 跳到帧 Inspect expressions display 远程debug 最早开始用eclipse的debug的时候,只会F5 F6 F ...
- HTML5中两种方法实现客户端存储数据
HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 之前,这些都是由 coo ...
- linux LVS (keepalived+ipvsadm)负载均衡搭建
ipsvadm 配置 一:安装配置 LVS+DR+Keepalivedclient 访问的地址 VIP 192.168.133.100 负载服务器master真实IP 192 ...
- Python读取文件文件夹并检索
import os import os.path f=open("Shouldlist.txt") ShouldList=[] while 1: line =f.readline( ...
- centos7 中文输入法设置
安装centos7 后,他有自带的中文输入法安装包找到 applications->systemTools->settings->region&language 2:在 in ...
- Codeforces 14D Two Paths 树的直径
题目链接:点击打开链接 题意:给定一棵树 找2条点不反复的路径,使得两路径的长度乘积最大 思路: 1.为了保证点不反复,在图中删去一条边,枚举这条删边 2.这样得到了2个树,在各自的树中找最长链.即树 ...
- EasyUI分页(前台分页和后台分页)
整理一下以前的总结: 分页包括前台分页和后台分页两种,针对数据量比较小的,比如说单位,角色等,可以使用前台分页,而针对日志文件这些,需要后台分页. 先说说前台分页吧: function pagerFi ...
- My sql 5.7 安装及错误解决
安装MYSQL5.7时,一直不能启动服务,找了N多办法,一直在围绕MY.INI文件来改来改去. 实际情况是,PATH路径设置完成后(计算机——属性—高级设置-环境变量——path),要执行以下命令初始 ...
- umbraco v7.6.4 surface controller not found 大深坑!
注意在修改后台地址过程中对于web.config里的umbracoPath 如果你改成了~/admin,surface controller的路由就变成了 /admin/surface/{contro ...
- Coursera machine learning 第二周 quiz 答案 Octave/Matlab Tutorial
https://www.coursera.org/learn/machine-learning/exam/dbM1J/octave-matlab-tutorial Octave Tutorial 5 ...