题目描述

在 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. MyEclipse6.5的速度性能优化大提速(转)

    MyEclipse是Eclipse的插件,也是一款功能强大的J2EE集成开发环境,支持代码编写.配置.测试以及除错.现在看一下MyEclipse6.5版本的速度性能优化大提速.优化MyEclipse6 ...

  2. CMake编译OpenCV

    使用CMake来编译OpenCV,以匹配自己使用的VS版本. 主要有两步: CMake编译OpenCV源码得到OpenCV.sln工程文件. VS编译OpenCV.sln. 以最新的cmake-3.1 ...

  3. apply, bind, call--绑定this的方法

    Function.prototype.call(),Function.prototype.apply(),Function.prototype.bind() 是三种改变函数内部this指向(即函数执行 ...

  4. 小米oj 判断是否为连乘数字串

     判断是否为连乘数字串 序号:#32难度:非常难时间限制:1000ms内存限制:10M 描述 给出一个字符串S,判断S是否为连乘字符串. 连乘字符串定义为: 字符串拆分成若干数字,后面的数字(从第三个 ...

  5. assert 笔记

    目录 什么是assert? assert使用 assert错误使用 什么是assert? Python 的 assert 语句是一个 debug 的好工具,主要用于测试一个条件是否满足.如果测试的条件 ...

  6. 日期与时间(C/C++)

    C++继承了C语言用于日期和时间操作的结构和函数,使用之前程序要引用<ctime>头文件 有四个与时间相关的类型:clock_t.time_t.size_t.和tm.类型clock_t.s ...

  7. python 输出三角形

    pattern = input("请输入你要选择的模式:") while True: if pattern == "A": row = eval(input(& ...

  8. Jquery 2.0+版本不支持IE8,如何解决?

    用了JQuery2.0+以后,在IE8下会报错,下面是我的方法. 先看代码: <!--[if !IE]> -->        <script src="/Scrip ...

  9. Leetcode题目102.二叉树的层次遍历(队列-中等)

    题目描述: 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如: 给定二叉树: [3,9,20,null,null,15,7], 3 / \ 9 20 / \ 15 ...

  10. Linux设备驱动程序 之 休眠

    休眠简介 当一个进程被置入休眠时,它会被标记为一种特殊状态,并从调度器的运行队列中移走:直到某些情况下修改了这个状态,进程才会在任意cpu上调度,即运行该进程:休眠中的进程会被搁置在一边,等待将来的某 ...