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 ...
随机推荐
- 【Excle数据透视表】如何按照地区交替填充背景颜色
现存在如下数据透视表 需要根据地区填充不同的背景颜色 步骤 选定数值区域→开始→条件格式→新建规则,出现如下窗口: 公式:=MOD(COUNT(1/(MATCH($A$4:$A4,$A$4:$A4,) ...
- JavaScript 判断浏览器及版本
/* 智能机浏览器版本信息: alert("语言版本: "+browser.language); alert(" 是否为移动终端: "+browser.vers ...
- $on、$emit和$broadcast的使用
$emit只能向parent controller传递event与data( $emit(name, args) ) $broadcast只能向child controller传递event与data ...
- web service json 数组解析
boolean workexpMark = true; // 美发师工作经历json数组解析 org.json.JSONObject jsonObject = new org.j ...
- junit测试时报No runnable methods错误的解决方法
1.因为你@Test时import的是@org.testng.annotations.Test所以会报错 解决方法:改为import org.junit.Test;就可以了
- 华为nova3超级慢动作酷玩抖音,没有办法我就是这么强大!
华为nova3超级慢动作酷玩抖音,没有办法我就是这么强大! 在华为最新发布的nova 3手机上,抖音通过华为himedia SDK集成了60fps.超级慢动作等华为媒体开放能力,在加持这些能力后,抖音 ...
- implicitly declaring function 'malloc' with type void *(unsigned long ) 错误 解决
errror : implicitly declaring function 'malloc' with type void *(unsigned long ) Be sure to includ ...
- 使用Istio治理微服务入门
近两年微服务架构流行,主流互联网厂商内部都已经微服务化,初创企业虽然技术积淀不行,但也通过各种开源工具拥抱微服务.再加上容器技术赋能,Kubernetes又添了一把火,微服务架构已然成为当前软件架构设 ...
- JQ 修改样式
//获取当前的url var url=document.location.href; var url_cn='http://www.macau-airport.com/cn/our-business/ ...
- COM对象模型
COM对象内存布局,多继承是虚继承吗? 接口之间怎么切换? 1) 是普通的多继承,不是虚继承.因为父类接口只是含有纯虚函数,不含任何数据成员,所以问题不大. 2) QueryInterface可以用来 ...