TOJ 4475: The Coolest Sub-matrix
4475: The Coolest Sub-matrix 
Total Submit: 50 Accepted:13
Description
Given an N*N matrix, find the coolest square sub-matrix.
We define the cool value of the square matrix as X-Y where X indicating the sum of all integers of the main diagonal and Y indicating the sum of the other diagonal.
Input
The first line has a positive integer N (2 ≤ N ≤ 400), the size of the matrix.
The following N lines each contain N integers in the range [-1000, 1000], the elements of the matrix.
Output
Output the coolest value of a square sub-matrix.
Sample Input
2
1 -2
4 5
Sample Output
4
Source
就是三重循环啊,大家怎么都不做,记得当时是我想错这个题了,导致当时我们队没有过这个题
就是让你随意在这个矩形选一个正方形矩阵,计算主对角线和副对角线的差值的最大值
只能枚举了,前缀和处理下,这个题只需要注意下标不一溢出就行了,思路还是很简单的,第i行j列结尾的k*k矩阵
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[][],b[][];
int main(){
int n;
scanf("%d",&n);
for(int i=;i<=n;i++)
for(int j=;j<=n;j++){
int x;
scanf("%d",&x);
a[i][j]=x+a[i-][j-];b[i][j]=x+b[i-][j+];
}
int ma=;
for(int i=;i<=n;i++)
for(int j=;j<=n;j++)
for(int k=;k<=i&&k<=j;k++)
ma=max(ma,a[i][j]-a[i-k][j-k]-b[i][j-k+]+b[i-k][j+]);
printf("%d\n",ma);
return ;
}
TOJ 4475: The Coolest Sub-matrix的更多相关文章
- 【TOJ 4475】The Coolest Sub-matrix(对角线前缀和)
描述 Given an N*N matrix, find the coolest square sub-matrix.We define the cool value of the square ma ...
- 最小生成树 TOJ 4117 Happy tree friends
链接http://acm.tju.edu.cn/toj/showp4117.html 4117. Happy tree friends Time Limit: 1.0 Seconds Memo ...
- TOJ 3365 ZOJ 3232 It's not Floyd Algorithm / 强连通分量
It's not Floyd Algorithm 时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte 描述 When a directed grap ...
- angular2系列教程(十一)路由嵌套、路由生命周期、matrix URL notation
今天我们要讲的是ng2的路由的第二部分,包括路由嵌套.路由生命周期等知识点. 例子 例子仍然是上节课的例子:
- Pramp mock interview (4th practice): Matrix Spiral Print
March 16, 2016 Problem statement:Given a 2D array (matrix) named M, print all items of M in a spiral ...
- Atitit Data Matrix dm码的原理与特点
Atitit Data Matrix dm码的原理与特点 Datamatrix原名Datacode,由美国国际资料公司(International Data Matrix, 简称ID Matrix)于 ...
- Android笔记——Matrix
转自:http://www.cnblogs.com/qiengo/archive/2012/06/30/2570874.html#translate Matrix的数学原理 在Android中,如果你 ...
- 通过Matrix进行二维图形仿射变换
Affine Transformation是一种二维坐标到二维坐标之间的线性变换,保持二维图形的"平直性"和"平行性".仿射变换可以通过一系列的原子变换的复合来 ...
- [LeetCode] Kth Smallest Element in a Sorted Matrix 有序矩阵中第K小的元素
Given a n x n matrix where each of the rows and columns are sorted in ascending order, find the kth ...
随机推荐
- AmazeUI 保存浏览器数据 永久性
//保存永久缓存数据function SaveAmuiStore(ItemName, ItemData){ if (window.localStorage) { var store = $.AMUI. ...
- ubuntu快捷键收集
Ctrl+Alt+T 终端 -Ctrl+Shift+C 终端复制 -Ctrl+Shift+V 终端粘贴 -Ctrl+L 清屏 -Ctrl+; 从剪切板中获得输入提示(不小心点到被诡异的提示吓到了) - ...
- google kickstart 2018 round D A Candies
思路: 对于small数据,由于求和及奇数数量两个限制条件均满足区间单调性,可以直接使用尺取法(滑动窗口法)求解. 对于large数据,奇数数量依然是满足区间单调性的.首先使用尺取法,找到所有满足奇数 ...
- 自定义Mega菜单的巧妙实现
查看了<云制造>官网源码,为其mega菜单的巧妙实现打call. 其另辟蹊径,采取父级主控分支的方法,仅对父级“增加/删除”控制标识,从而控制子层显示. <!DOCTYPE html ...
- uvm_reg_sequence——寄存器模型(六)
寄存器模型 uvm_reg_sequence是UVM自带所有register sequence 的基类. 该类包含model, adapter, reg_seqr(uvm_sequencer). 感觉 ...
- import 何时使用 "" 和<> Objective-C
Objective-C在这方面与C/C ++相似.引号是给local本地包含的文件的.(你需要指明相对现有文件的相对路径的).而对于尖括号来说,是一个全局路径. 一般情况下引号用在引用自己项目中的类的 ...
- HDU 4276 The Ghost Blows Light (树形DP,变形)
题意:给定一棵n个节点的树,起点是1,终点是n,每经过一条边需要消耗Ti天,每个点上有一定量的珠宝,要求必须在t天内到达终点才可以将珠宝带出去,问至多能带多少珠宝? 思路: 注意Ti可以为0,而且有可 ...
- (转)SpringMVC学习(二)——SpringMVC架构及组件
http://blog.csdn.net/yerenyuan_pku/article/details/72231385 相信大家通过前文的学习,已经对SpringMVC这个框架多少有些理解了.还记得上 ...
- 47.Number of Islands(岛的数量)
Level: Medium 题目描述: Given a 2d grid map of '1's (land) and '0's (water), count the number of islan ...
- for..in...时,注意hasOwnProperty验证
for..in...时,注意hasOwnProperty验证 var obj = { a: 10, b: 20 }; // 注意词句代码 Object.prototype.c = 30; var it ...