题目描述

在 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. Zookeeper:Zookeeper集群概要

    1.下载解压zookeeper 使用官网的(http://zookeeper.apache.org/releases.html#download)推荐下载镜像https://mirrors.tuna. ...

  2. 并发编程入门(一): POSIX 使用互斥量和条件变量实现生产者/消费者问题

    boost的mutex,condition_variable非常好用.但是在Linux上,boost实际上做的是对pthread_mutex_t和pthread_cond_t的一系列的封装.因此通过对 ...

  3. Django基础之cookie

    1. Cookie 1.1 Cookie的由来 大家都知道HTTP协议是无状态的.无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系, 它不会受前面的请求响应情况 ...

  4. Python基础之集合set

    集合是无序的,不重复的数据集合,它里面的元素是可哈希的(不可变类型), 但是集合本身是不可哈希的(所以集合做不了字典的键)的. 以下是集合最重要的两点: (1)去重,把一个列表变成集合,就自动去重了. ...

  5. CentOS7遇到问题总结

    问题1.保护多库版本:libstdc++-4.8.5-28.el7_5.1.i686 != libstdc++-4.8.5-28.el7.x86_64 错误:保护多库版本:libgcc-4.8.5-2 ...

  6. html,css,js实现的一个钟表

    效果如图: 实现代码: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  7. java实现二维码的生成与解析

    简单介绍下二维码:二维码其实就是一种编码技术,只是这种编码技术是用在图片上了,将给定的一些文字,数字转换为一张经过特定编码的图片,而解析二维码则相反,就是将一张经过编码的图片解析为数字或者文字. 当然 ...

  8. Linux设备驱动程序 之 自旋锁

    概念 自旋锁可以再不能休眠的代码中使用,比如中断处理例程:在正确使用的情况下,自旋锁通常可以提供比信号量更高的性能: 一个自旋锁是一个互斥设备,它只能由两个值,锁定和解锁:通常实现为某个整数值中的单个 ...

  9. PHPStorm2017去掉函数参数提示

    今天升级到 PHPStorm 2017.1 发现增加了好些新功能, 有个默认开启的参数名和类型提示功能, 虽然功能挺强大的, 不过我用不着, 还是关掉的好, 有同样需求的同学可以看看 例子比较特殊这么 ...

  10. 博客&git收藏

    阿里中间件团队博客 http://jm.taobao.orgkimmking https://blog.csdn.net/KimmKing/article/details/71517053 greys ...