题目描述

在 x 轴上有相互挨着的矩形, 这些矩形有一个边紧贴着 x 轴,现在给出每个矩形的长宽, 所有的矩形看作整体当作一个画布, 则可以在这个画布上画出的最大的矩形的面积是多少。(画出的矩形长和高平行于X,Y轴)

解答要求时间限制:3000ms, 内存限制:64MB
输入

每组第一个数N(0<=N<=20000)表示N个矩形。下面N行有两个数a(1 <= a <=1000),b(1 <= b<=1000)分别表示每个矩形的x轴长度和y轴长度。

输出

输出最大的面积。

#include <stdio.h>

long dynamicCaculate(int size);

long x_and_y[][] = {};

int main() {
int n;
scanf("%d", &n);
long i = ;
while (i < n) {
scanf("%d %d", &x_and_y[i][], &x_and_y[i][]);
i++;
}
long res = dynamicCaculate(n);
printf("%ld", res);
return ;
} //分包不包括下一个输入的矩形
long dynamicCaculate(int size) {
if (size == ) {
return ;
}
long res_1 = ;
for (int i = ; i < size; ++i) {
long tempArea = ;
int totalWidth = x_and_y[i][];
for (int j = i - ; j >= ; --j) {
if (x_and_y[j][] >= x_and_y[i][]) {
totalWidth += x_and_y[j][];
} else {
break;
}
}
for (int j = i + ; j < size; ++j) {
if (x_and_y[j][] >= x_and_y[i][]) {
totalWidth += x_and_y[j][];
} else {
break;
}
}
tempArea = totalWidth * x_and_y[i][];
res_1 = res_1 > tempArea ? res_1 : tempArea;
}
return res_1;
}

Rectangle的更多相关文章

  1. [LeetCode] Perfect Rectangle 完美矩形

    Given N axis-aligned rectangles where N > 0, determine if they all together form an exact cover o ...

  2. [LeetCode] Max Sum of Rectangle No Larger Than K 最大矩阵和不超过K

    Given a non-empty 2D matrix matrix and an integer k, find the max sum of a rectangle in the matrix s ...

  3. [LeetCode] Smallest Rectangle Enclosing Black Pixels 包含黑像素的最小矩阵

    An image is represented by a binary matrix with 0 as a white pixel and 1 as a black pixel. The black ...

  4. [LeetCode] Rectangle Area 矩形面积

    Find the total area covered by two rectilinear rectangles in a2D plane. Each rectangle is defined by ...

  5. [LeetCode] Maximal Rectangle 最大矩形

    Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle containing all ones and ...

  6. [LeetCode] Largest Rectangle in Histogram 直方图中最大的矩形

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  7. Maximal Rectangle

    很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965 分为两步:把原矩阵转为直方图,再用largest rectangle ...

  8. 85. Maximal Rectangle

    85. Maximal Rectangle Given a 2D binary matrix filled with 0's and 1's, find the largest rectangle c ...

  9. poj 2559 Largest Rectangle in a Histogram - 单调栈

    Largest Rectangle in a Histogram Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19782 ...

  10. LeetCode 笔记系列 17 Largest Rectangle in Histogram

    题目: Largest Rectangle in Histogram Given n non-negative integers representing the histogram's bar he ...

随机推荐

  1. 给程序添加git commit信息

    遇到了一个客户程序出问题,自己这边始终无法重现的bug.为了检查问题,查到了一个添加git的commit信息到程序中的方法,感觉对程序版本控制十分好用. 一,项目中添加如下文件 文件结构: GitVe ...

  2. springboot中使用spring security,登录url就出现403错误

    参考链接:https://segmentfault.com/q/1010000012743613 有两个controller,一个是所有用户可以访问的@RequestMapping("use ...

  3. 获取link后的参数值

    getQueryString:function(name){ var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i ...

  4. node中的stream(流)内置模块

    stream是Node.js提供的又一个仅在服务区端可用的模块,目的是支持“流”这种数据结构. 什么是流?流是一种抽象的数据结构.想象水流,当在水管中流动时,就可以从某个地方(例如自来水厂)源源不断地 ...

  5. Apache反向代理解析二级目录/泛目录教程/apache反向代理/apache泛目录反向代理

    同nginx一样,apache解析目录不需要安装任何东西,在配置文件里加入解析规则即可.解析规则: <IfModule mod_proxy.c> ProxyPreserveHost On ...

  6. [linux]kali apt-get 安装mysql

    环境: Linux kali 4.18.0-kali2-amd64 #1 SMP Debian 4.18.10-2kali1 (2018-10-09) x86_64 GNU/Linux 本来是想要装m ...

  7. shell基础之二 bash特性详解

    https://blog.51cto.com/13520779/2093146 合格linux运维人员必会的30道shell编程面试题及讲解:https://blog.51cto.com/oldboy ...

  8. Nginx之HTTP过滤模块

    1. HTTP 过滤模块 ngx_http_not_modified_module 仅对 HTTP 头部做处理.在返回 200 成功时,根据请求中 If-Modified-Since 或者 If-Un ...

  9. js的dom操作(整理)(转)

    js的dom操作整理(整理)(转) 一.总结 一句话总结: dom操作有用原生js的dom操作,也可以用对js封装过的jquery等插件来来更加方便的进行dom操作 1.dom是什么? 对于JavaS ...

  10. nginx状态码

    200:服务器成功返回网页 403:服务器拒绝请求.404:请求的网页不存在 499:客户端主动断开了连接.500:服务器遇到错误,无法完成请求.502:服务器作为网关或代理,从上游服务器收到无效响应 ...