4475: The Coolest Sub-matrix 

Time Limit(Common/Java):4000MS/12000MS     Memory Limit:65536KByte
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

TOJ

就是三重循环啊,大家怎么都不做,记得当时是我想错这个题了,导致当时我们队没有过这个题

就是让你随意在这个矩形选一个正方形矩阵,计算主对角线和副对角线的差值的最大值

只能枚举了,前缀和处理下,这个题只需要注意下标不一溢出就行了,思路还是很简单的,第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 ;
}

最新文章

  1. Android数据库相关整理
  2. Git避免输入用户名和密码
  3. 关于分布式事务的一个误解:使用了TransactionScope就一定会开启分布式事务吗?
  4. JAVA查找--[二分查找]
  5. 关于json的理解
  6. POJ 2240 &amp;&amp; ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
  7. json 得到时分秒为00:00:00,拿不到时分秒 解决办法
  8. BUAA 更大公约数
  9. 将List 中的ConvertAll的使用:List 中的元素转换,List模型转换, list模型转数组
  10. Android单元测试之一:基本概念
  11. ORACLE设置用户密码不过期
  12. SpringBoot集成Dubbo
  13. iOS开源项目之日志框架CocoaLumberjack
  14. Android `AsyncTask`简要分析
  15. OpenMP基础使用
  16. Javascript 严格模式下几个禁忌
  17. Ubuntu 18.04上安装R及Rstudio
  18. logback错误日志发送邮件
  19. module.exports 、exports、export、export default的区别
  20. windows远程连接设置

热门文章

  1. C# 枚举类型的描述信息获取
  2. PeopleSoft FSCM Production Support 案例分析
  3. Ubuntu安装新英伟达驱动出现问题解决方法
  4. nGrinder技术架构图
  5. spark 的RDD各种转换和动作
  6. iOS的设计备忘录/资源集合(新手快速开发)
  7. CPP-基础:关于多态
  8. spark 省份次数统计实例
  9. 【414】Code::Blocks增加主题
  10. |chromosomal walk |zoo blot|鉴定疾病gene|