IT公司100题-35- 求一个矩阵中最大的二维矩阵(元素和最大)

时间:2021-11-17 00:22:51
问题描述:
求一个矩阵中最大的二维矩阵(元素和最大).如:
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 (规律 &plus; 二维矩阵的前缀和妙用)

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

  2. &lbrack;LeetCode&rsqb; 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. &lbrack;CareerCup&rsqb; 11&period;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. &lbrack;LeetCode&rsqb; 240&period; 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. &lbrack;LeetCode&rsqb; 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值&comma;同时列出键&comma;值

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

  7. &lbrack;LeetCode&rsqb; 74&period; 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 &colon;搜索二维矩阵

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

随机推荐

  1. 精通AngularJS 读书笔记(2)

    AngularJS 速成 视图 因为AngularJS 依靠浏览器去解析模板,所以要保证模板是有效的HTML.尤其要小心闭合号HTML标签(未闭合好的标签不会产生任何错误信息,但会让视图不能正确渲染) ...

  2. MMORPG大型游戏设计与开发(概述)updated

    1.定义 MMORPG,是英文Massive(或Massively)Multiplayer Online Role-PlayingGame的缩写,即大型多人在线角色扮演游戏. 2.技术与知识 在这系列 ...

  3. UESTC 1817 Complete Building the Houses

    Complete Building the Houses Time Limit: 2000MS Memory Limit: 65535KB 64bit IO Format: %lld & %l ...

  4. &lbrack;Android Training视频系列&rsqb; 8&period;3 Dealing with Audio Output Hardware

    用户在播放音乐的时候有多个选择,可以使用内置的扬声器,有线耳机或者是支持A2DP的蓝牙耳机.(补充:A2DP全名是Advanced Audio Distribution Profile 蓝牙音频传输模 ...

  5. jquery获取form表单内容以及绑定数据到form表单

    在日常开发的过程中,难免会用到form表单,我们需要获取表单的数据保存到数据库,或者拿到后台的一串json数据,要将数据绑定到form表单上,这里我写了一个基于jquery的,formHelp插件,使 ...

  6. Android屏幕适配问题详解

    上篇-Android本地化资源目录详解 :http://www.cnblogs.com/steffen/p/3833048.html 单位: px(像素):屏幕上的点. in(英寸):长度单位. mm ...

  7. promise原理

      简介 Promise 对象用于延迟(deferred) 计算和异步(asynchronous )计算.一个Promise对象代表着一个还未完成,但预期将来会完成的操作.Promise 对象是一个返 ...

  8. golang包管理工具glide安装

    1:下载安装glide go get github.com/Masterminds/glide glide的源码以及exe文件在第一个gopath目录,如果不知道哪个是第一个gopath,echo一下 ...

  9. Kafka的安装是否成功的简单测试命令

    首先了解一下kafka的基本概念 .1. BrokerKafka集群包含一个或多个服务器,这种服务器被称为broker2. Topic每条发布到Kafka集群的消息都有一个类别,这个类别被称为Topi ...

  10. 关于对Access数据库的学习报告

    学习Access数据库的报告 一.前言 一开始我对access一窍不通,甚至不知道它是干什么的,后来经过网上资料的查阅对它略有了解.microsoft office access是由微软发布的关联式数 ...