题目描述

在 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. access denied

    背景: 想要使用nginx转发 实现一个输出PHPinfo的页面, 比如: 访问  aaa.com/phpinfo  浏览器显示phpinfo的信息, 因为有的时候需要查看phpinfo, 所以想单独 ...

  2. 【线性代数】2-2:消元(Eliminate)

    title: [线性代数]2-2:消元(Eliminate) toc: true categories: Mathematic Linear Algebra date: 2017-08-31 16:1 ...

  3. python 装饰器,传递类以及参数

    #!/usr/bin/env python # coding=utf- import time #import redis class RedisLock(object): def __init__( ...

  4. hdu5492

    hdu5492 陈大哥的毒瘤题T1 题意: 差不多就是根据题意推式子,求最小方差. 解法: 首先,可以观察到,如果我们直接暴力去取平均数,很大概率会取出来小数,所以一个很直观的想法就是把平均数从式子里 ...

  5. linux查看当前目录

    查看当前路径命令:pwd pwd命令能够显示当前所处的路径. 这个命令比较简单,如果有时在操作过程中忘记了当前的路径,则可以通过此命令来查看路径,其执行方式为:

  6. linux下编译利用CMakeLists.txt 编译C++写的opencv程序

    https://hihozhou.com/blog/2017/05/11/linux-compile-opencv-c++-file.html cmake . make -j8

  7. CISCO实验记录四:备份路由器的IOS

    1.配置好TFTP服务器(假设ip为192.168.2.1) 2.查看当前IOS名称 #show version 输出中有一段:System image file is "bootflash ...

  8. 【零基础】为什么Facebook发币就不一样

    参考: https://baijiahao.baidu.com/s?id=1637182596912694597&wfr=spider&for=pc https://blog.csdn ...

  9. 使用editcap.exe分割pcap文件

    特别提示:本人博客部分有参考网络其他博客,但均是本人亲手编写过并验证通过.如发现博客有错误,请及时提出以免误导其他人,谢谢!欢迎转载,但记得标明文章出处:http://www.cnblogs.com/ ...

  10. Centos7 yum安装mysql(完整版)

    1.下载mysql 地址:https://dev.mysql.com/downloads/repo/yum/.选择对应版本下载.