问题描述:
求一个矩阵中最大的二维矩阵(元素和最大).如:
1 2 3 4 5
6 7 8 9 10
1 2 3 4 5
中最大的是:
4 5
9 10
 
分析:
2*2子数组的最大和。遍历求和,时间复杂度为O(mn)。
 

代码实现:

 // 35.cc
#include <iostream>
#include <climits>
using namespace std; int find_max(int (*a)[], int m, int n) {
int max_sum = INT_MIN;
int sum; for (int i = ; i < m - ; i++) {
for (int j = ; j < n - ; j++) {
sum = a[i][j] + a[i+][j] + a[i][j+] + a[i+][j+];
max_sum = max(max_sum, sum);
}
}
return max_sum;
} int main() {
int a[][] = {{, , , , }, {, , , , }, {, , , , }};
cout << find_max(a, , ) << endl;
return ;
}

IT公司100题-35- 求一个矩阵中最大的二维矩阵(元素和最大)的更多相关文章

  1. HDU 6336 (规律 + 二维矩阵的前缀和妙用)

    题目 给出长度为n 的A矩阵 , 按 int cursor = 0; for (int i = 0; ; ++i) { for (int j = 0; j <= i; ++j) { M[j][i ...

  2. [LeetCode] Search a 2D Matrix II 搜索一个二维矩阵之二

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  3. [CareerCup] 11.6 Search a 2D Matrix 搜索一个二维矩阵

    11.6 Given an M x N matrix in which each row and each column is sorted in ascending order, write a m ...

  4. [LeetCode] 240. Search a 2D Matrix II 搜索一个二维矩阵 II

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  5. [LeetCode] Search a 2D Matrix 搜索一个二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  6. 求一个Map中最大的value值,同时列出键,值

    求一个Map中最大的value值,同时列出键,值 方法1. public static void main(String[] args){  Map map=new HashMap();  map.p ...

  7. [LeetCode] 74. Search a 2D Matrix 搜索一个二维矩阵

    Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the follo ...

  8. 《剑指Offer》第1题(Java实现):在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。

    一.题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该 ...

  9. lintcode :搜索二维矩阵

    题目: 搜索二维矩阵 写出一个高效的算法来搜索 m × n矩阵中的值. 这个矩阵具有以下特性: 每行中的整数从左到右是排序的. 每行的第一个数大于上一行的最后一个整数. 样例 考虑下列矩阵: [ [1 ...

随机推荐

  1. nodejs框架express实现登录

    目录: 访问视图 Post请求 Post请求 - body(1) Post请求 - body(2) Post登陆1 Post登陆2 页面访问控制1 页面访问控制2 访问视图 前面我们已经添加了视图模板 ...

  2. Pandas将中文数据集转换为数值类别型数据集

    一个机器学习竞赛中,题目大意如下,本文主要记录数据处理过程,为了模型训练,第一步需要将中文数据集处理为数值类别数据集保存. 基于大数据的运营商投诉与故障关联分析 目标:原始数据集是含大量中文的xls格 ...

  3. 搭建android开发环境

    任何一个程序的开端都要从搭建开发环境开始,这样你就可以进行实战练习了,并且搭建完后即快速来一个项目HelloWorld, 哈哈,话不多说了,进入正题 android环境的安装主要分3步骤: 1.下载和 ...

  4. Case1:WorkFlow不能运行的解决办法

    原因为CRMAppPool选择了一个域用户,然后异步服务的用户执行会有问题 at CrmException..ctor(Int32 errorCode, Object[] arguments) ilO ...

  5. [windows][C++][库]遍历删除文件夹

    #include"windows.h"#include"string.h" BOOL IsDirectory(const char *pDir) { ]; Ze ...

  6. placeholder兼容ie8

    <script type="text/javascript">     if( !('placeholder' in document.createElement('i ...

  7. AES对称加密和解密

    package demo.security; import java.io.IOException; import java.io.UnsupportedEncodingException; impo ...

  8. 【前端】String.prototype.match() 用法详解

    var str="1 plus 2 equal 3" // 正则表达式 console.log(str.match(/\d+/g)); // ["1", &qu ...

  9. 怎样在excel中添加下拉列表框

    用excel2013打开要编辑的工作表,例子是一个班级名单,可以看到政治面貌目前还没有填写   接着我们找一个空白处,依次写入政治面貌的可能选项: 群众.共青团员   然后选中“政治面貌”这一列,点击 ...

  10. Openstack+Kubernetes+Docker微服务实践之路--基础设施

    近两年微服务在网上聊的如此的如火如荼,备受关注,我在去年下半年的一个项目中也用到了阿里云的EDAS.HSF,深有体会,最近时间空闲出于好奇,决定一探究竟打算自建微服务平台,基本实现EDAS.HSF的功 ...