TOJ 4475: The Coolest Sub-matrix
2024-09-04 15:59:07
4475: The Coolest Sub-matrix
Time Limit(Common/Java):4000MS/12000MS Memory Limit:65536KByte
Total Submit: 50 Accepted:13
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 ;
}
最新文章
- Android数据库相关整理
- Git避免输入用户名和密码
- 关于分布式事务的一个误解:使用了TransactionScope就一定会开启分布式事务吗?
- JAVA查找--[二分查找]
- 关于json的理解
- POJ 2240 &;&; ZOJ 1082 Arbitrage 最短路,c++ stl pass g++ tle 难度:0
- json 得到时分秒为00:00:00,拿不到时分秒 解决办法
- BUAA 更大公约数
- 将List 中的ConvertAll的使用:List 中的元素转换,List模型转换, list模型转数组
- Android单元测试之一:基本概念
- ORACLE设置用户密码不过期
- SpringBoot集成Dubbo
- iOS开源项目之日志框架CocoaLumberjack
- Android `AsyncTask`简要分析
- OpenMP基础使用
- Javascript 严格模式下几个禁忌
- Ubuntu 18.04上安装R及Rstudio
- logback错误日志发送邮件
- module.exports 、exports、export、export default的区别
- windows远程连接设置