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 ...
随机推荐
- BundleConfig包含js,css失败
今天在做mvc项目的时候,引入了bootstrap样式.但是包含css和js的时候出错了 于是我查阅资料,好多人都说后缀名前面不能包含".",于是我把min前面的".&q ...
- link标签的media属性的用法
<link rel=stylesheet" type="text/css" href="print.css" media="scree ...
- 浅谈C++ 内存泄漏及其检测工具
浅谈C++ 内存泄漏及其检测工具 http://wenku.baidu.com/link?url=1DGkOOvd_ITZyB8IHAwfhCOx2tfO6id8UfuyQkAMHZU6sasaAXz ...
- 声明已被否决 VS C++
error C4996声明已被否决,不止一次碰到这个问题,在这里必须mark一下! 尝试这个1.Project Properties > Configuration Properties > ...
- winform重绘
1.重绘文字#多行文字a.先定义一个矩形 Rectangle p1 = , , , this.Height); Rectangle p2 = , , , this.Height); Rectangle ...
- A*算法研究
许多工业与科学计算问题都可以转化为在图中寻路问题.启发式的寻路方法将问题表示为一个图,然后利用问题本身的信息,来加速解的搜索过程.一个典型的例子是有一些通路连接若干城市,找出从指定起点城市到指定终点城 ...
- VM虚拟机下的Linux不能上网
虚拟机linux上网配置 图解教程 首先查看window7主机下的网络配置VMNet1或VMNet8是否开启,其实linux系统的网络连接跟linux系统一致 在虚拟机界面将桥接改为NAT连接 点虚拟 ...
- [BZOJ3631]:[JLOI2014]松鼠的新家(LCA+树上差分)
题目传送门 题目描述: 松鼠的新家是一棵树,前几天刚刚装修了新家,新家有n个房间,并且有n-1根树枝连接,每个房间都可以相互到达,且俩个房间之间的路线都是唯一的.天哪,他居然真的住在“树”上.松鼠想邀 ...
- Bootstrap历练实例:表单控件大小
表单控件大小 您可以分别使用 class .input-lg 和 .col-lg-* 来设置表单的高度和宽度. 实例: <!DOCTYPE html><html><hea ...
- 两种常见JS面向象写法
基于构造函数 function Circle(r) { this.r = r; } Circle.PI = 3.14159; Circle.prototype.area = function() { ...